From ee7ac6602b7d4f073d59c331425144337220ef12 Mon Sep 17 00:00:00 2001 From: Ruben Ayrapetyan Date: Thu, 4 Dec 2014 16:57:45 +0300 Subject: [PATCH] Fixing insertion to lookup cache: removing possibility of invalidation of entry during it's initialization, skipping empty entries during search for entry containing specified property. --- src/libecmaobjects/ecma-alloc.c | 3 --- src/libecmaobjects/ecma-gc.c | 3 +++ src/libecmaobjects/ecma-lcache.c | 13 ++++++++++--- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/libecmaobjects/ecma-alloc.c b/src/libecmaobjects/ecma-alloc.c index 750c0d944..44873f4e0 100644 --- a/src/libecmaobjects/ecma-alloc.c +++ b/src/libecmaobjects/ecma-alloc.c @@ -16,7 +16,6 @@ #include "ecma-alloc.h" #include "ecma-globals.h" #include "ecma-gc.h" -#include "ecma-lcache.h" #include "globals.h" #include "mem-poolman.h" @@ -65,8 +64,6 @@ JERRY_STATIC_ASSERT (sizeof (ecma_label_descriptor_t) == sizeof (uint64_t)); return p ## ecma_type; \ } \ \ - ecma_lcache_invalidate_all (); \ - \ for (ecma_gc_gen_t gen_id = ECMA_GC_GEN_0; \ gen_id < ECMA_GC_GEN_COUNT; \ gen_id++) \ diff --git a/src/libecmaobjects/ecma-gc.c b/src/libecmaobjects/ecma-gc.c index cafc239e0..e2a87cd22 100644 --- a/src/libecmaobjects/ecma-gc.c +++ b/src/libecmaobjects/ecma-gc.c @@ -28,6 +28,7 @@ #include "ecma-globals.h" #include "ecma-gc.h" #include "ecma-helpers.h" +#include "ecma-lcache.h" #include "globals.h" #include "jerry-libc.h" #include "jrt-bit-fields.h" @@ -525,6 +526,8 @@ ecma_gc_sweep (ecma_object_t *object_p) /**< object to free */ void ecma_gc_run (ecma_gc_gen_t max_gen_to_collect) /**< maximum generation to run collection on */ { + ecma_lcache_invalidate_all (); + JERRY_ASSERT(max_gen_to_collect < ECMA_GC_GEN_COUNT); /* clearing visited flags for all objects of generations to be processed */ diff --git a/src/libecmaobjects/ecma-lcache.c b/src/libecmaobjects/ecma-lcache.c index 921b3f83b..77db05a3a 100644 --- a/src/libecmaobjects/ecma-lcache.c +++ b/src/libecmaobjects/ecma-lcache.c @@ -147,6 +147,8 @@ ecma_lcache_insert (ecma_object_t *object_p, /**< object */ JERRY_ASSERT (object_p != NULL); JERRY_ASSERT (prop_name_p != NULL); + prop_name_p = ecma_copy_or_ref_ecma_string (prop_name_p); + ecma_string_hash_t hash_key = ecma_string_hash (prop_name_p); if (prop_p != NULL) @@ -159,8 +161,14 @@ ecma_lcache_insert (ecma_object_t *object_p, /**< object */ int32_t entry_index; for (entry_index = 0; entry_index < ECMA_LCACHE_HASH_ROW_LENGTH; entry_index++) { - if (ecma_lcache_hash_table[hash_key][entry_index].prop_cp == prop_cp) + if (ecma_lcache_hash_table[hash_key][entry_index].object_cp != ECMA_NULL_POINTER + && ecma_lcache_hash_table[hash_key][entry_index].prop_cp == prop_cp) { +#ifndef JERRY_NDEBUG + ecma_object_t* obj_in_entry_p; + obj_in_entry_p = ECMA_GET_NON_NULL_POINTER (ecma_lcache_hash_table[hash_key][entry_index].object_cp); + JERRY_ASSERT (obj_in_entry_p == object_p); +#endif /* !JERRY_NDEBUG */ break; } } @@ -195,8 +203,7 @@ ecma_lcache_insert (ecma_object_t *object_p, /**< object */ ecma_ref_object (object_p); ECMA_SET_NON_NULL_POINTER (ecma_lcache_hash_table[ hash_key ][ entry_index ].object_cp, object_p); - ECMA_SET_NON_NULL_POINTER (ecma_lcache_hash_table[ hash_key ][ entry_index ].prop_name_cp, - ecma_copy_or_ref_ecma_string (prop_name_p)); + ECMA_SET_NON_NULL_POINTER (ecma_lcache_hash_table[ hash_key ][ entry_index ].prop_name_cp, prop_name_p); ECMA_SET_POINTER (ecma_lcache_hash_table[ hash_key ][ entry_index ].prop_cp, prop_p); } /* ecma_lcache_insert */