Skip to content

Merge lcache into context #2498

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 0 additions & 9 deletions jerry-core/api/jerry.c
Original file line number Diff line number Diff line change
Expand Up @@ -2648,10 +2648,6 @@ jerry_create_instance (uint32_t heap_size, /**< the size of heap */
total_size += heap_size;
#endif /* !JERRY_SYSTEM_ALLOCATOR */

#ifndef CONFIG_ECMA_LCACHE_DISABLE
total_size += sizeof (jerry_hash_table_t);
#endif /* !CONFIG_ECMA_LCACHE_DISABLE */

total_size = JERRY_ALIGNUP (total_size, JMEM_ALIGNMENT);

jerry_instance_t *instance_p = (jerry_instance_t *) alloc (total_size, cb_data_p);
Expand All @@ -2674,11 +2670,6 @@ jerry_create_instance (uint32_t heap_size, /**< the size of heap */
byte_p += heap_size;
#endif /* !JERRY_SYSTEM_ALLOCATOR */

#ifndef CONFIG_ECMA_LCACHE_DISABLE
instance_p->lcache_p = byte_p;
byte_p += sizeof (jerry_hash_table_t);
#endif /* !JERRY_SYSTEM_ALLOCATOR */

JERRY_ASSERT (byte_p <= ((uint8_t *) instance_p) + total_size);

JERRY_UNUSED (byte_p);
Expand Down
1 change: 0 additions & 1 deletion jerry-core/ecma/base/ecma-alloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
#include "ecma-alloc.h"
#include "ecma-globals.h"
#include "ecma-gc.h"
#include "ecma-lcache.h"
#include "jrt.h"
#include "jmem.h"

Expand Down
1 change: 0 additions & 1 deletion jerry-core/ecma/base/ecma-gc.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
#include "ecma-globals.h"
#include "ecma-gc.h"
#include "ecma-helpers.h"
#include "ecma-lcache.h"
#include "ecma-property-hashmap.h"
#include "jcontext.h"
#include "jrt.h"
Expand Down
1 change: 0 additions & 1 deletion jerry-core/ecma/base/ecma-helpers-string.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
#include "ecma-gc.h"
#include "ecma-globals.h"
#include "ecma-helpers.h"
#include "ecma-lcache.h"
#include "jrt.h"
#include "jrt-libc-includes.h"
#include "lit-char-helpers.h"
Expand Down
2 changes: 0 additions & 2 deletions jerry-core/ecma/base/ecma-init-finalize.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
#include "ecma-gc.h"
#include "ecma-helpers.h"
#include "ecma-init-finalize.h"
#include "ecma-lcache.h"
#include "ecma-lex-env.h"
#include "ecma-literal-storage.h"
#include "jmem.h"
Expand All @@ -36,7 +35,6 @@
void
ecma_init (void)
{
ecma_lcache_init ();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the cache cleared along the context?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, jerry_init clears all the context with memset. Now that lcache is part of the context, it's initialization is also handled there.

ecma_init_global_lex_env ();

jmem_register_free_unused_memory_callback (ecma_free_unused_memory);
Expand Down
29 changes: 5 additions & 24 deletions jerry-core/ecma/base/ecma-lcache.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,20 +33,6 @@
*/
#define ECMA_LCACHE_HASH_MASK (ECMA_LCACHE_HASH_ROWS_COUNT - 1)

#endif /* !CONFIG_ECMA_LCACHE_DISABLE */

/**
* Initialize LCache
*/
void
ecma_lcache_init (void)
{
#ifndef CONFIG_ECMA_LCACHE_DISABLE
memset (JERRY_HASH_TABLE_CONTEXT (table), 0, sizeof (jerry_hash_table_t));
#endif /* !CONFIG_ECMA_LCACHE_DISABLE */
} /* ecma_lcache_init */

#ifndef CONFIG_ECMA_LCACHE_DISABLE
/**
* Invalidate specified LCache entry
*/
Expand Down Expand Up @@ -74,6 +60,7 @@ ecma_lcache_row_index (jmem_cpointer_t object_cp, /**< compressed pointer to obj
* so properties of different objects with the same name can be cached effectively. */
return (size_t) ((name_hash ^ object_cp) & ECMA_LCACHE_HASH_MASK);
} /* ecma_lcache_row_index */

#endif /* !CONFIG_ECMA_LCACHE_DISABLE */

/**
Expand All @@ -96,7 +83,7 @@ ecma_lcache_insert (ecma_object_t *object_p, /**< object */

lit_string_hash_t name_hash = ecma_string_get_property_name_hash (*prop_p, name_cp);
size_t row_index = ecma_lcache_row_index (object_cp, name_hash);
ecma_lcache_hash_entry_t *entries_p = JERRY_HASH_TABLE_CONTEXT (table)[row_index];
ecma_lcache_hash_entry_t *entries_p = JERRY_CONTEXT (lcache) [row_index];

uint32_t entry_index;
for (entry_index = 0; entry_index < ECMA_LCACHE_HASH_ROW_LENGTH; entry_index++)
Expand Down Expand Up @@ -132,12 +119,6 @@ ecma_lcache_insert (ecma_object_t *object_p, /**< object */
#endif /* !CONFIG_ECMA_LCACHE_DISABLE */
} /* ecma_lcache_insert */

#ifndef CONFIG_ECMA_LCACHE_DISABLE



#endif /* !CONFIG_ECMA_LCACHE_DISABLE */

/**
* Lookup property in the LCache
*
Expand Down Expand Up @@ -182,7 +163,7 @@ ecma_lcache_lookup (ecma_object_t *object_p, /**< object */

size_t row_index = ecma_lcache_row_index (object_cp, name_hash);

ecma_lcache_hash_entry_t *entry_p = JERRY_HASH_TABLE_CONTEXT (table) [row_index];
ecma_lcache_hash_entry_t *entry_p = JERRY_CONTEXT (lcache) [row_index];
ecma_lcache_hash_entry_t *entry_end_p = entry_p + ECMA_LCACHE_HASH_ROW_LENGTH;

while (entry_p < entry_end_p)
Expand Down Expand Up @@ -230,12 +211,12 @@ ecma_lcache_invalidate (ecma_object_t *object_p, /**< object */

lit_string_hash_t name_hash = ecma_string_get_property_name_hash (*prop_p, name_cp);
size_t row_index = ecma_lcache_row_index (object_cp, name_hash);
ecma_lcache_hash_entry_t *entry_p = JERRY_HASH_TABLE_CONTEXT (table) [row_index];
ecma_lcache_hash_entry_t *entry_p = JERRY_CONTEXT (lcache) [row_index];

while (true)
{
/* The property must be present. */
JERRY_ASSERT (entry_p - JERRY_HASH_TABLE_CONTEXT (table) [row_index] < ECMA_LCACHE_HASH_ROW_LENGTH);
JERRY_ASSERT (entry_p - JERRY_CONTEXT (lcache) [row_index] < ECMA_LCACHE_HASH_ROW_LENGTH);

if (entry_p->object_cp != ECMA_NULL_POINTER && entry_p->prop_p == prop_p)
{
Expand Down
1 change: 0 additions & 1 deletion jerry-core/ecma/base/ecma-lcache.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
* @{
*/

void ecma_lcache_init (void);
void ecma_lcache_insert (ecma_object_t *object_p, jmem_cpointer_t name_cp, ecma_property_t *prop_p);
ecma_property_t *ecma_lcache_lookup (ecma_object_t *object_p, const ecma_string_t *prop_name_p);
void ecma_lcache_invalidate (ecma_object_t *object_p, jmem_cpointer_t name_cp, ecma_property_t *prop_p);
Expand Down
1 change: 0 additions & 1 deletion jerry-core/ecma/operations/ecma-objects-arguments.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
#include "ecma-gc.h"
#include "ecma-globals.h"
#include "ecma-helpers.h"
#include "ecma-lcache.h"
#include "ecma-lex-env.h"
#include "ecma-objects.h"
#include "ecma-objects-arguments.h"
Expand Down
1 change: 0 additions & 1 deletion jerry-core/ecma/operations/ecma-objects.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
#include "ecma-gc.h"
#include "ecma-globals.h"
#include "ecma-function-object.h"
#include "ecma-lcache.h"
#include "ecma-lex-env.h"
#include "ecma-string-object.h"
#include "ecma-objects-arguments.h"
Expand Down
8 changes: 0 additions & 8 deletions jerry-core/jcontext/jcontext.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,6 @@ jerry_context_t jerry_global_context;
jmem_heap_t jerry_global_heap JERRY_ATTR_ALIGNED (JMEM_ALIGNMENT) JERRY_GLOBAL_HEAP_SECTION;
#endif /* !JERRY_SYSTEM_ALLOCATOR */

#ifndef CONFIG_ECMA_LCACHE_DISABLE

/**
* Global hash table.
*/
jerry_hash_table_t jerry_global_hash_table;

#endif /* !CONFIG_ECMA_LCACHE_DISABLE */
#endif /* !JERRY_ENABLE_EXTERNAL_CONTEXT */

/**
Expand Down
45 changes: 4 additions & 41 deletions jerry-core/jcontext/jcontext.h
Original file line number Diff line number Diff line change
Expand Up @@ -131,17 +131,13 @@ typedef struct
#ifdef JMEM_STATS
jmem_heap_stats_t jmem_heap_stats; /**< heap's memory usage statistics */
#endif /* JMEM_STATS */
} jerry_context_t;

/* This must be at the end of the context for performance reasons */
#ifndef CONFIG_ECMA_LCACHE_DISABLE
/**
* Hash table for caching the last access of properties.
*/
typedef struct
{
ecma_lcache_hash_entry_t table[ECMA_LCACHE_HASH_ROWS_COUNT][ECMA_LCACHE_HASH_ROW_LENGTH];
} jerry_hash_table_t;
/** hash table for caching the last access of properties */
ecma_lcache_hash_entry_t lcache[ECMA_LCACHE_HASH_ROWS_COUNT][ECMA_LCACHE_HASH_ROW_LENGTH];
#endif /* !CONFIG_ECMA_LCACHE_DISABLE */
} jerry_context_t;

#ifdef JERRY_ENABLE_EXTERNAL_CONTEXT

Expand Down Expand Up @@ -173,9 +169,6 @@ struct jerry_instance_t
jmem_heap_t *heap_p; /**< point to the heap aligned to JMEM_ALIGNMENT. */
uint32_t heap_size; /**< size of the heap */
#endif /* !JERRY_SYSTEM_ALLOCATOR */
#ifndef CONFIG_ECMA_LCACHE_DISABLE
uint8_t *lcache_p; /**< point to the entrance of the lcache in buffer */
#endif /* !CONFIG_ECMA_LCACHE_DISABLE */
};

#define JERRY_CONTEXT(field) (JERRY_GET_CURRENT_INSTANCE ()->context.field)
Expand All @@ -200,18 +193,6 @@ jerry_context_get_current_heap (void)

#endif /* !JERRY_SYSTEM_ALLOCATOR */

#ifndef CONFIG_ECMA_LCACHE_DISABLE

static inline jerry_hash_table_t * JERRY_ATTR_ALWAYS_INLINE
jerry_context_get_current_lcache (void)
{
return (jerry_hash_table_t *) (JERRY_GET_CURRENT_INSTANCE ()->lcache_p);
} /* jerry_context_get_current_lcache */

#define JERRY_HASH_TABLE_CONTEXT(field) (jerry_context_get_current_lcache ()->field)

#endif /* !CONFIG_ECMA_LCACHE_DISABLE */

#else /* !JERRY_ENABLE_EXTERNAL_CONTEXT */

/**
Expand Down Expand Up @@ -253,15 +234,6 @@ extern jerry_context_t jerry_global_context;
extern jmem_heap_t jerry_global_heap;
#endif /* !JERRY_SYSTEM_ALLOCATOR */

#ifndef CONFIG_ECMA_LCACHE_DISABLE

/**
* Global hash table.
*/
extern jerry_hash_table_t jerry_global_hash_table;

#endif /* !CONFIG_ECMA_LCACHE_DISABLE */

/**
* Provides a reference to a field in the current context.
*/
Expand All @@ -275,15 +247,6 @@ extern jerry_hash_table_t jerry_global_hash_table;

#endif /* !JERRY_SYSTEM_ALLOCATOR */

#ifndef CONFIG_ECMA_LCACHE_DISABLE

/**
* Provides a reference to the global hash table.
*/
#define JERRY_HASH_TABLE_CONTEXT(field) (jerry_global_hash_table.field)

#endif /* !CONFIG_ECMA_LCACHE_DISABLE */

#endif /* JERRY_ENABLE_EXTERNAL_CONTEXT */

/**
Expand Down