v8  3.25.30(node0.11.13)
V8 is Google's open source JavaScript engine
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
test-constantpool.cc
Go to the documentation of this file.
1 // Copyright 2013 the V8 project authors. All rights reserved.
2 
3 // Test constant pool array code.
4 
5 #include "v8.h"
6 
7 #include "factory.h"
8 #include "objects.h"
9 #include "cctest.h"
10 
11 using namespace v8::internal;
12 
13 
15  CompileRun("function foo() {};");
18  (*context)->Global()->Get(v8_str("foo"))));
19  return fun->code();
20 }
21 
22 
23 TEST(ConstantPool) {
24  LocalContext context;
25  Isolate* isolate = CcTest::i_isolate();
26  Heap* heap = isolate->heap();
27  Factory* factory = isolate->factory();
28  v8::HandleScope scope(context->GetIsolate());
29 
30  // Check construction.
31  Handle<ConstantPoolArray> array = factory->NewConstantPoolArray(3, 1, 2, 1);
32  CHECK_EQ(array->count_of_int64_entries(), 3);
33  CHECK_EQ(array->count_of_code_ptr_entries(), 1);
34  CHECK_EQ(array->count_of_heap_ptr_entries(), 2);
35  CHECK_EQ(array->count_of_int32_entries(), 1);
36  CHECK_EQ(array->length(), 7);
37  CHECK_EQ(array->first_int64_index(), 0);
38  CHECK_EQ(array->first_code_ptr_index(), 3);
39  CHECK_EQ(array->first_heap_ptr_index(), 4);
40  CHECK_EQ(array->first_int32_index(), 6);
41 
42  // Check getters and setters.
43  int64_t big_number = V8_2PART_UINT64_C(0x12345678, 9ABCDEF0);
44  Handle<Object> object = factory->NewHeapNumber(4.0);
45  Code* code = DummyCode(&context);
46  array->set(0, big_number);
47  array->set(1, 0.5);
48  array->set(2, 3e-24);
49  array->set(3, code->entry());
50  array->set(4, code);
51  array->set(5, *object);
52  array->set(6, 50);
53  CHECK_EQ(array->get_int64_entry(0), big_number);
54  CHECK_EQ(array->get_int64_entry_as_double(1), 0.5);
55  CHECK_EQ(array->get_int64_entry_as_double(2), 3e-24);
56  CHECK_EQ(array->get_code_ptr_entry(3), code->entry());
57  CHECK_EQ(array->get_heap_ptr_entry(4), code);
58  CHECK_EQ(array->get_heap_ptr_entry(5), *object);
59  CHECK_EQ(array->get_int32_entry(6), 50);
60 
61  // Check pointers are updated on GC.
62  Object* old_ptr = array->get_heap_ptr_entry(5);
63  CHECK_EQ(*object, old_ptr);
65  Object* new_ptr = array->get_heap_ptr_entry(5);
66  CHECK_NE(*object, old_ptr);
67  CHECK_EQ(*object, new_ptr);
68 }
#define CHECK_EQ(expected, value)
Definition: checks.h:252
Code * DummyCode(LocalContext *context)
Factory * factory()
Definition: isolate.h:995
v8::Isolate * GetIsolate()
Definition: api.cc:5233
Handle< HeapNumber > NewHeapNumber(double value, PretenureFlag pretenure=NOT_TENURED)
Definition: factory.cc:1022
enable upcoming ES6 features enable harmony block scoping enable harmony enable harmony proxies enable harmony generators enable harmony numeric enable harmony string enable harmony math functions harmony_scoping harmony_symbols harmony_collections harmony_iteration harmony_strings harmony_scoping harmony_maths tracks arrays with only smi values Optimize object Array DOM strings and string pretenure call new trace pretenuring decisions of HAllocate instructions track fields with only smi values track fields with heap values track_fields track_fields Enables optimizations which favor memory size over execution speed use string slices optimization filter maximum number of GVN fix point iterations use function inlining use allocation folding eliminate write barriers targeting allocations in optimized code maximum source size in bytes considered for a single inlining maximum cumulative number of AST nodes considered for inlining crankshaft harvests type feedback from stub cache trace check elimination phase hydrogen tracing filter trace hydrogen to given file name trace inlining decisions trace store elimination trace all use positions trace global value numbering trace hydrogen escape analysis trace the tracking of allocation sites trace map generalization environment for every instruction deoptimize every n garbage collections put a break point before deoptimizing deoptimize uncommon cases use on stack replacement trace array bounds check elimination perform array index dehoisting use load elimination use store elimination use constant folding eliminate unreachable code number of stress runs when picking a function to watch for shared function not JSFunction itself flushes the cache of optimized code for closures on every GC functions with arguments object maximum number of escape analysis fix point iterations allow uint32 values on optimize frames if they are used only in safe operations track concurrent recompilation artificial compilation delay in ms concurrent on stack replacement do not emit check maps for constant values that have a leaf deoptimize the optimized code if the layout of the maps changes number of stack frames inspected by the profiler percentage of ICs that must have type info to allow optimization extra verbose compilation tracing generate extra code(assertions) for debugging") DEFINE_bool(code_comments
static i::Isolate * i_isolate()
Definition: cctest.h:102
#define V8_2PART_UINT64_C(a, b)
Definition: globals.h:226
static v8::internal::Handle< To > OpenHandle(v8::Local< From > handle)
Definition: api.h:308
#define CHECK_NE(unexpected, value)
Definition: checks.h:256
bool CollectGarbage(AllocationSpace space, const char *gc_reason=NULL, const GCCallbackFlags gc_callback_flags=kNoGCCallbackFlags)
Definition: heap-inl.h:554
Handle< ConstantPoolArray > NewConstantPoolArray(int number_of_int64_entries, int number_of_code_ptr_entries, int number_of_heap_ptr_entries, int number_of_int32_entries)
Definition: factory.cc:90
Definition: v8.h:124