Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(592)

Side by Side Diff: test/cctest/test-heap.cc

Issue 6685088: Merge isolates to bleeding_edge. (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: '' Created 9 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « test/cctest/test-func-name-inference.cc ('k') | test/cctest/test-heap-profiler.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2006-2008 the V8 project authors. All rights reserved. 1 // Copyright 2006-2008 the V8 project authors. All rights reserved.
2 2
3 #include <stdlib.h> 3 #include <stdlib.h>
4 4
5 #include "v8.h" 5 #include "v8.h"
6 6
7 #include "execution.h" 7 #include "execution.h"
8 #include "factory.h" 8 #include "factory.h"
9 #include "macro-assembler.h" 9 #include "macro-assembler.h"
10 #include "global-handles.h" 10 #include "global-handles.h"
11 #include "cctest.h" 11 #include "cctest.h"
12 12
13 using namespace v8::internal; 13 using namespace v8::internal;
14 14
15 static v8::Persistent<v8::Context> env; 15 static v8::Persistent<v8::Context> env;
16 16
17 static void InitializeVM() { 17 static void InitializeVM() {
18 if (env.IsEmpty()) env = v8::Context::New(); 18 if (env.IsEmpty()) env = v8::Context::New();
19 v8::HandleScope scope; 19 v8::HandleScope scope;
20 env->Enter(); 20 env->Enter();
21 } 21 }
22 22
23 23
24 static void CheckMap(Map* map, int type, int instance_size) { 24 static void CheckMap(Map* map, int type, int instance_size) {
25 CHECK(map->IsHeapObject()); 25 CHECK(map->IsHeapObject());
26 #ifdef DEBUG 26 #ifdef DEBUG
27 CHECK(Heap::Contains(map)); 27 CHECK(HEAP->Contains(map));
28 #endif 28 #endif
29 CHECK_EQ(Heap::meta_map(), map->map()); 29 CHECK_EQ(HEAP->meta_map(), map->map());
30 CHECK_EQ(type, map->instance_type()); 30 CHECK_EQ(type, map->instance_type());
31 CHECK_EQ(instance_size, map->instance_size()); 31 CHECK_EQ(instance_size, map->instance_size());
32 } 32 }
33 33
34 34
35 TEST(HeapMaps) { 35 TEST(HeapMaps) {
36 InitializeVM(); 36 InitializeVM();
37 CheckMap(Heap::meta_map(), MAP_TYPE, Map::kSize); 37 CheckMap(HEAP->meta_map(), MAP_TYPE, Map::kSize);
38 CheckMap(Heap::heap_number_map(), HEAP_NUMBER_TYPE, HeapNumber::kSize); 38 CheckMap(HEAP->heap_number_map(), HEAP_NUMBER_TYPE, HeapNumber::kSize);
39 CheckMap(Heap::fixed_array_map(), FIXED_ARRAY_TYPE, kVariableSizeSentinel); 39 CheckMap(HEAP->fixed_array_map(), FIXED_ARRAY_TYPE, kVariableSizeSentinel);
40 CheckMap(Heap::string_map(), STRING_TYPE, kVariableSizeSentinel); 40 CheckMap(HEAP->string_map(), STRING_TYPE, kVariableSizeSentinel);
41 } 41 }
42 42
43 43
44 static void CheckOddball(Object* obj, const char* string) { 44 static void CheckOddball(Object* obj, const char* string) {
45 CHECK(obj->IsOddball()); 45 CHECK(obj->IsOddball());
46 bool exc; 46 bool exc;
47 Object* print_string = *Execution::ToString(Handle<Object>(obj), &exc); 47 Object* print_string = *Execution::ToString(Handle<Object>(obj), &exc);
48 CHECK(String::cast(print_string)->IsEqualTo(CStrVector(string))); 48 CHECK(String::cast(print_string)->IsEqualTo(CStrVector(string)));
49 } 49 }
50 50
51 51
52 static void CheckSmi(int value, const char* string) { 52 static void CheckSmi(int value, const char* string) {
53 bool exc; 53 bool exc;
54 Object* print_string = 54 Object* print_string =
55 *Execution::ToString(Handle<Object>(Smi::FromInt(value)), &exc); 55 *Execution::ToString(Handle<Object>(Smi::FromInt(value)), &exc);
56 CHECK(String::cast(print_string)->IsEqualTo(CStrVector(string))); 56 CHECK(String::cast(print_string)->IsEqualTo(CStrVector(string)));
57 } 57 }
58 58
59 59
60 static void CheckNumber(double value, const char* string) { 60 static void CheckNumber(double value, const char* string) {
61 Object* obj = Heap::NumberFromDouble(value)->ToObjectChecked(); 61 Object* obj = HEAP->NumberFromDouble(value)->ToObjectChecked();
62 CHECK(obj->IsNumber()); 62 CHECK(obj->IsNumber());
63 bool exc; 63 bool exc;
64 Object* print_string = *Execution::ToString(Handle<Object>(obj), &exc); 64 Object* print_string = *Execution::ToString(Handle<Object>(obj), &exc);
65 CHECK(String::cast(print_string)->IsEqualTo(CStrVector(string))); 65 CHECK(String::cast(print_string)->IsEqualTo(CStrVector(string)));
66 } 66 }
67 67
68 68
69 static void CheckFindCodeObject() { 69 static void CheckFindCodeObject() {
70 // Test FindCodeObject 70 // Test FindCodeObject
71 #define __ assm. 71 #define __ assm.
72 72
73 Assembler assm(NULL, 0); 73 Assembler assm(NULL, 0);
74 74
75 __ nop(); // supported on all architectures 75 __ nop(); // supported on all architectures
76 76
77 CodeDesc desc; 77 CodeDesc desc;
78 assm.GetCode(&desc); 78 assm.GetCode(&desc);
79 Object* code = Heap::CreateCode( 79 Object* code = HEAP->CreateCode(
80 desc, 80 desc,
81 Code::ComputeFlags(Code::STUB), 81 Code::ComputeFlags(Code::STUB),
82 Handle<Object>(Heap::undefined_value()))->ToObjectChecked(); 82 Handle<Object>(HEAP->undefined_value()))->ToObjectChecked();
83 CHECK(code->IsCode()); 83 CHECK(code->IsCode());
84 84
85 HeapObject* obj = HeapObject::cast(code); 85 HeapObject* obj = HeapObject::cast(code);
86 Address obj_addr = obj->address(); 86 Address obj_addr = obj->address();
87 87
88 for (int i = 0; i < obj->Size(); i += kPointerSize) { 88 for (int i = 0; i < obj->Size(); i += kPointerSize) {
89 Object* found = Heap::FindCodeObject(obj_addr + i); 89 Object* found = HEAP->FindCodeObject(obj_addr + i);
90 CHECK_EQ(code, found); 90 CHECK_EQ(code, found);
91 } 91 }
92 92
93 Object* copy = Heap::CreateCode( 93 Object* copy = HEAP->CreateCode(
94 desc, 94 desc,
95 Code::ComputeFlags(Code::STUB), 95 Code::ComputeFlags(Code::STUB),
96 Handle<Object>(Heap::undefined_value()))->ToObjectChecked(); 96 Handle<Object>(HEAP->undefined_value()))->ToObjectChecked();
97 CHECK(copy->IsCode()); 97 CHECK(copy->IsCode());
98 HeapObject* obj_copy = HeapObject::cast(copy); 98 HeapObject* obj_copy = HeapObject::cast(copy);
99 Object* not_right = Heap::FindCodeObject(obj_copy->address() + 99 Object* not_right = HEAP->FindCodeObject(obj_copy->address() +
100 obj_copy->Size() / 2); 100 obj_copy->Size() / 2);
101 CHECK(not_right != code); 101 CHECK(not_right != code);
102 } 102 }
103 103
104 104
105 TEST(HeapObjects) { 105 TEST(HeapObjects) {
106 InitializeVM(); 106 InitializeVM();
107 107
108 v8::HandleScope sc; 108 v8::HandleScope sc;
109 Object* value = Heap::NumberFromDouble(1.000123)->ToObjectChecked(); 109 Object* value = HEAP->NumberFromDouble(1.000123)->ToObjectChecked();
110 CHECK(value->IsHeapNumber()); 110 CHECK(value->IsHeapNumber());
111 CHECK(value->IsNumber()); 111 CHECK(value->IsNumber());
112 CHECK_EQ(1.000123, value->Number()); 112 CHECK_EQ(1.000123, value->Number());
113 113
114 value = Heap::NumberFromDouble(1.0)->ToObjectChecked(); 114 value = HEAP->NumberFromDouble(1.0)->ToObjectChecked();
115 CHECK(value->IsSmi()); 115 CHECK(value->IsSmi());
116 CHECK(value->IsNumber()); 116 CHECK(value->IsNumber());
117 CHECK_EQ(1.0, value->Number()); 117 CHECK_EQ(1.0, value->Number());
118 118
119 value = Heap::NumberFromInt32(1024)->ToObjectChecked(); 119 value = HEAP->NumberFromInt32(1024)->ToObjectChecked();
120 CHECK(value->IsSmi()); 120 CHECK(value->IsSmi());
121 CHECK(value->IsNumber()); 121 CHECK(value->IsNumber());
122 CHECK_EQ(1024.0, value->Number()); 122 CHECK_EQ(1024.0, value->Number());
123 123
124 value = Heap::NumberFromInt32(Smi::kMinValue)->ToObjectChecked(); 124 value = HEAP->NumberFromInt32(Smi::kMinValue)->ToObjectChecked();
125 CHECK(value->IsSmi()); 125 CHECK(value->IsSmi());
126 CHECK(value->IsNumber()); 126 CHECK(value->IsNumber());
127 CHECK_EQ(Smi::kMinValue, Smi::cast(value)->value()); 127 CHECK_EQ(Smi::kMinValue, Smi::cast(value)->value());
128 128
129 value = Heap::NumberFromInt32(Smi::kMaxValue)->ToObjectChecked(); 129 value = HEAP->NumberFromInt32(Smi::kMaxValue)->ToObjectChecked();
130 CHECK(value->IsSmi()); 130 CHECK(value->IsSmi());
131 CHECK(value->IsNumber()); 131 CHECK(value->IsNumber());
132 CHECK_EQ(Smi::kMaxValue, Smi::cast(value)->value()); 132 CHECK_EQ(Smi::kMaxValue, Smi::cast(value)->value());
133 133
134 #ifndef V8_TARGET_ARCH_X64 134 #ifndef V8_TARGET_ARCH_X64
135 // TODO(lrn): We need a NumberFromIntptr function in order to test this. 135 // TODO(lrn): We need a NumberFromIntptr function in order to test this.
136 value = Heap::NumberFromInt32(Smi::kMinValue - 1)->ToObjectChecked(); 136 value = HEAP->NumberFromInt32(Smi::kMinValue - 1)->ToObjectChecked();
137 CHECK(value->IsHeapNumber()); 137 CHECK(value->IsHeapNumber());
138 CHECK(value->IsNumber()); 138 CHECK(value->IsNumber());
139 CHECK_EQ(static_cast<double>(Smi::kMinValue - 1), value->Number()); 139 CHECK_EQ(static_cast<double>(Smi::kMinValue - 1), value->Number());
140 #endif 140 #endif
141 141
142 MaybeObject* maybe_value = 142 MaybeObject* maybe_value =
143 Heap::NumberFromUint32(static_cast<uint32_t>(Smi::kMaxValue) + 1); 143 HEAP->NumberFromUint32(static_cast<uint32_t>(Smi::kMaxValue) + 1);
144 value = maybe_value->ToObjectChecked(); 144 value = maybe_value->ToObjectChecked();
145 CHECK(value->IsHeapNumber()); 145 CHECK(value->IsHeapNumber());
146 CHECK(value->IsNumber()); 146 CHECK(value->IsNumber());
147 CHECK_EQ(static_cast<double>(static_cast<uint32_t>(Smi::kMaxValue) + 1), 147 CHECK_EQ(static_cast<double>(static_cast<uint32_t>(Smi::kMaxValue) + 1),
148 value->Number()); 148 value->Number());
149 149
150 // nan oddball checks 150 // nan oddball checks
151 CHECK(Heap::nan_value()->IsNumber()); 151 CHECK(HEAP->nan_value()->IsNumber());
152 CHECK(isnan(Heap::nan_value()->Number())); 152 CHECK(isnan(HEAP->nan_value()->Number()));
153 153
154 Handle<String> s = Factory::NewStringFromAscii(CStrVector("fisk hest ")); 154 Handle<String> s = FACTORY->NewStringFromAscii(CStrVector("fisk hest "));
155 CHECK(s->IsString()); 155 CHECK(s->IsString());
156 CHECK_EQ(10, s->length()); 156 CHECK_EQ(10, s->length());
157 157
158 String* object_symbol = String::cast(Heap::Object_symbol()); 158 String* object_symbol = String::cast(HEAP->Object_symbol());
159 CHECK(Top::context()->global()->HasLocalProperty(object_symbol)); 159 CHECK(
160 Isolate::Current()->context()->global()->HasLocalProperty(object_symbol));
160 161
161 // Check ToString for oddballs 162 // Check ToString for oddballs
162 CheckOddball(Heap::true_value(), "true"); 163 CheckOddball(HEAP->true_value(), "true");
163 CheckOddball(Heap::false_value(), "false"); 164 CheckOddball(HEAP->false_value(), "false");
164 CheckOddball(Heap::null_value(), "null"); 165 CheckOddball(HEAP->null_value(), "null");
165 CheckOddball(Heap::undefined_value(), "undefined"); 166 CheckOddball(HEAP->undefined_value(), "undefined");
166 167
167 // Check ToString for Smis 168 // Check ToString for Smis
168 CheckSmi(0, "0"); 169 CheckSmi(0, "0");
169 CheckSmi(42, "42"); 170 CheckSmi(42, "42");
170 CheckSmi(-42, "-42"); 171 CheckSmi(-42, "-42");
171 172
172 // Check ToString for Numbers 173 // Check ToString for Numbers
173 CheckNumber(1.1, "1.1"); 174 CheckNumber(1.1, "1.1");
174 175
175 CheckFindCodeObject(); 176 CheckFindCodeObject();
(...skipping 14 matching lines...) Expand all
190 CHECK(Smi::FromInt(Smi::kMinValue)->IsSmi()); 191 CHECK(Smi::FromInt(Smi::kMinValue)->IsSmi());
191 CHECK(Smi::FromInt(Smi::kMaxValue)->IsSmi()); 192 CHECK(Smi::FromInt(Smi::kMaxValue)->IsSmi());
192 } 193 }
193 194
194 195
195 TEST(GarbageCollection) { 196 TEST(GarbageCollection) {
196 InitializeVM(); 197 InitializeVM();
197 198
198 v8::HandleScope sc; 199 v8::HandleScope sc;
199 // Check GC. 200 // Check GC.
200 Heap::CollectGarbage(NEW_SPACE); 201 HEAP->CollectGarbage(NEW_SPACE);
201 202
202 Handle<String> name = Factory::LookupAsciiSymbol("theFunction"); 203 Handle<String> name = FACTORY->LookupAsciiSymbol("theFunction");
203 Handle<String> prop_name = Factory::LookupAsciiSymbol("theSlot"); 204 Handle<String> prop_name = FACTORY->LookupAsciiSymbol("theSlot");
204 Handle<String> prop_namex = Factory::LookupAsciiSymbol("theSlotx"); 205 Handle<String> prop_namex = FACTORY->LookupAsciiSymbol("theSlotx");
205 Handle<String> obj_name = Factory::LookupAsciiSymbol("theObject"); 206 Handle<String> obj_name = FACTORY->LookupAsciiSymbol("theObject");
206 207
207 { 208 {
208 v8::HandleScope inner_scope; 209 v8::HandleScope inner_scope;
209 // Allocate a function and keep it in global object's property. 210 // Allocate a function and keep it in global object's property.
210 Handle<JSFunction> function = 211 Handle<JSFunction> function =
211 Factory::NewFunction(name, Factory::undefined_value()); 212 FACTORY->NewFunction(name, FACTORY->undefined_value());
212 Handle<Map> initial_map = 213 Handle<Map> initial_map =
213 Factory::NewMap(JS_OBJECT_TYPE, JSObject::kHeaderSize); 214 FACTORY->NewMap(JS_OBJECT_TYPE, JSObject::kHeaderSize);
214 function->set_initial_map(*initial_map); 215 function->set_initial_map(*initial_map);
215 Top::context()->global()->SetProperty( 216 Isolate::Current()->context()->global()->SetProperty(
216 *name, *function, NONE, kNonStrictMode)->ToObjectChecked(); 217 *name, *function, NONE, kNonStrictMode)->ToObjectChecked();
217 // Allocate an object. Unrooted after leaving the scope. 218 // Allocate an object. Unrooted after leaving the scope.
218 Handle<JSObject> obj = Factory::NewJSObject(function); 219 Handle<JSObject> obj = FACTORY->NewJSObject(function);
219 obj->SetProperty( 220 obj->SetProperty(
220 *prop_name, Smi::FromInt(23), NONE, kNonStrictMode)->ToObjectChecked(); 221 *prop_name, Smi::FromInt(23), NONE, kNonStrictMode)->ToObjectChecked();
221 obj->SetProperty( 222 obj->SetProperty(
222 *prop_namex, Smi::FromInt(24), NONE, kNonStrictMode)->ToObjectChecked(); 223 *prop_namex, Smi::FromInt(24), NONE, kNonStrictMode)->ToObjectChecked();
223 224
224 CHECK_EQ(Smi::FromInt(23), obj->GetProperty(*prop_name)); 225 CHECK_EQ(Smi::FromInt(23), obj->GetProperty(*prop_name));
225 CHECK_EQ(Smi::FromInt(24), obj->GetProperty(*prop_namex)); 226 CHECK_EQ(Smi::FromInt(24), obj->GetProperty(*prop_namex));
226 } 227 }
227 228
228 Heap::CollectGarbage(NEW_SPACE); 229 HEAP->CollectGarbage(NEW_SPACE);
229 230
230 // Function should be alive. 231 // Function should be alive.
231 CHECK(Top::context()->global()->HasLocalProperty(*name)); 232 CHECK(Isolate::Current()->context()->global()->HasLocalProperty(*name));
232 // Check function is retained. 233 // Check function is retained.
233 Object* func_value = 234 Object* func_value = Isolate::Current()->context()->global()->
234 Top::context()->global()->GetProperty(*name)->ToObjectChecked(); 235 GetProperty(*name)->ToObjectChecked();
235 CHECK(func_value->IsJSFunction()); 236 CHECK(func_value->IsJSFunction());
236 Handle<JSFunction> function(JSFunction::cast(func_value)); 237 Handle<JSFunction> function(JSFunction::cast(func_value));
237 238
238 { 239 {
239 HandleScope inner_scope; 240 HandleScope inner_scope;
240 // Allocate another object, make it reachable from global. 241 // Allocate another object, make it reachable from global.
241 Handle<JSObject> obj = Factory::NewJSObject(function); 242 Handle<JSObject> obj = FACTORY->NewJSObject(function);
242 Top::context()->global()->SetProperty( 243 Isolate::Current()->context()->global()->SetProperty(
243 *obj_name, *obj, NONE, kNonStrictMode)->ToObjectChecked(); 244 *obj_name, *obj, NONE, kNonStrictMode)->ToObjectChecked();
244 obj->SetProperty( 245 obj->SetProperty(
245 *prop_name, Smi::FromInt(23), NONE, kNonStrictMode)->ToObjectChecked(); 246 *prop_name, Smi::FromInt(23), NONE, kNonStrictMode)->ToObjectChecked();
246 } 247 }
247 248
248 // After gc, it should survive. 249 // After gc, it should survive.
249 Heap::CollectGarbage(NEW_SPACE); 250 HEAP->CollectGarbage(NEW_SPACE);
250 251
251 CHECK(Top::context()->global()->HasLocalProperty(*obj_name)); 252 CHECK(Isolate::Current()->context()->global()->HasLocalProperty(*obj_name));
252 CHECK(Top::context()->global()->GetProperty(*obj_name)->ToObjectChecked()-> 253 CHECK(Isolate::Current()->context()->global()->
253 IsJSObject()); 254 GetProperty(*obj_name)->ToObjectChecked()->IsJSObject());
254 Object* obj = 255 Object* obj = Isolate::Current()->context()->global()->
255 Top::context()->global()->GetProperty(*obj_name)->ToObjectChecked(); 256 GetProperty(*obj_name)->ToObjectChecked();
256 JSObject* js_obj = JSObject::cast(obj); 257 JSObject* js_obj = JSObject::cast(obj);
257 CHECK_EQ(Smi::FromInt(23), js_obj->GetProperty(*prop_name)); 258 CHECK_EQ(Smi::FromInt(23), js_obj->GetProperty(*prop_name));
258 } 259 }
259 260
260 261
261 static void VerifyStringAllocation(const char* string) { 262 static void VerifyStringAllocation(const char* string) {
262 v8::HandleScope scope; 263 v8::HandleScope scope;
263 Handle<String> s = Factory::NewStringFromUtf8(CStrVector(string)); 264 Handle<String> s = FACTORY->NewStringFromUtf8(CStrVector(string));
264 CHECK_EQ(StrLength(string), s->length()); 265 CHECK_EQ(StrLength(string), s->length());
265 for (int index = 0; index < s->length(); index++) { 266 for (int index = 0; index < s->length(); index++) {
266 CHECK_EQ(static_cast<uint16_t>(string[index]), s->Get(index)); 267 CHECK_EQ(static_cast<uint16_t>(string[index]), s->Get(index));
267 } 268 }
268 } 269 }
269 270
270 271
271 TEST(String) { 272 TEST(String) {
272 InitializeVM(); 273 InitializeVM();
273 274
274 VerifyStringAllocation("a"); 275 VerifyStringAllocation("a");
275 VerifyStringAllocation("ab"); 276 VerifyStringAllocation("ab");
276 VerifyStringAllocation("abc"); 277 VerifyStringAllocation("abc");
277 VerifyStringAllocation("abcd"); 278 VerifyStringAllocation("abcd");
278 VerifyStringAllocation("fiskerdrengen er paa havet"); 279 VerifyStringAllocation("fiskerdrengen er paa havet");
279 } 280 }
280 281
281 282
282 TEST(LocalHandles) { 283 TEST(LocalHandles) {
283 InitializeVM(); 284 InitializeVM();
284 285
285 v8::HandleScope scope; 286 v8::HandleScope scope;
286 const char* name = "Kasper the spunky"; 287 const char* name = "Kasper the spunky";
287 Handle<String> string = Factory::NewStringFromAscii(CStrVector(name)); 288 Handle<String> string = FACTORY->NewStringFromAscii(CStrVector(name));
288 CHECK_EQ(StrLength(name), string->length()); 289 CHECK_EQ(StrLength(name), string->length());
289 } 290 }
290 291
291 292
292 TEST(GlobalHandles) { 293 TEST(GlobalHandles) {
294 GlobalHandles* global_handles = Isolate::Current()->global_handles();
293 InitializeVM(); 295 InitializeVM();
294 296
295 Handle<Object> h1; 297 Handle<Object> h1;
296 Handle<Object> h2; 298 Handle<Object> h2;
297 Handle<Object> h3; 299 Handle<Object> h3;
298 Handle<Object> h4; 300 Handle<Object> h4;
299 301
300 { 302 {
301 HandleScope scope; 303 HandleScope scope;
302 304
303 Handle<Object> i = Factory::NewStringFromAscii(CStrVector("fisk")); 305 Handle<Object> i = FACTORY->NewStringFromAscii(CStrVector("fisk"));
304 Handle<Object> u = Factory::NewNumber(1.12344); 306 Handle<Object> u = FACTORY->NewNumber(1.12344);
305 307
306 h1 = GlobalHandles::Create(*i); 308 h1 = global_handles->Create(*i);
307 h2 = GlobalHandles::Create(*u); 309 h2 = global_handles->Create(*u);
308 h3 = GlobalHandles::Create(*i); 310 h3 = global_handles->Create(*i);
309 h4 = GlobalHandles::Create(*u); 311 h4 = global_handles->Create(*u);
310 } 312 }
311 313
312 // after gc, it should survive 314 // after gc, it should survive
313 Heap::CollectGarbage(NEW_SPACE); 315 HEAP->CollectGarbage(NEW_SPACE);
314 316
315 CHECK((*h1)->IsString()); 317 CHECK((*h1)->IsString());
316 CHECK((*h2)->IsHeapNumber()); 318 CHECK((*h2)->IsHeapNumber());
317 CHECK((*h3)->IsString()); 319 CHECK((*h3)->IsString());
318 CHECK((*h4)->IsHeapNumber()); 320 CHECK((*h4)->IsHeapNumber());
319 321
320 CHECK_EQ(*h3, *h1); 322 CHECK_EQ(*h3, *h1);
321 GlobalHandles::Destroy(h1.location()); 323 global_handles->Destroy(h1.location());
322 GlobalHandles::Destroy(h3.location()); 324 global_handles->Destroy(h3.location());
323 325
324 CHECK_EQ(*h4, *h2); 326 CHECK_EQ(*h4, *h2);
325 GlobalHandles::Destroy(h2.location()); 327 global_handles->Destroy(h2.location());
326 GlobalHandles::Destroy(h4.location()); 328 global_handles->Destroy(h4.location());
327 } 329 }
328 330
329 331
330 static bool WeakPointerCleared = false; 332 static bool WeakPointerCleared = false;
331 333
332 static void TestWeakGlobalHandleCallback(v8::Persistent<v8::Value> handle, 334 static void TestWeakGlobalHandleCallback(v8::Persistent<v8::Value> handle,
333 void* id) { 335 void* id) {
334 if (1234 == reinterpret_cast<intptr_t>(id)) WeakPointerCleared = true; 336 if (1234 == reinterpret_cast<intptr_t>(id)) WeakPointerCleared = true;
335 handle.Dispose(); 337 handle.Dispose();
336 } 338 }
337 339
338 340
339 TEST(WeakGlobalHandlesScavenge) { 341 TEST(WeakGlobalHandlesScavenge) {
342 GlobalHandles* global_handles = Isolate::Current()->global_handles();
340 InitializeVM(); 343 InitializeVM();
341 344
342 WeakPointerCleared = false; 345 WeakPointerCleared = false;
343 346
344 Handle<Object> h1; 347 Handle<Object> h1;
345 Handle<Object> h2; 348 Handle<Object> h2;
346 349
347 { 350 {
348 HandleScope scope; 351 HandleScope scope;
349 352
350 Handle<Object> i = Factory::NewStringFromAscii(CStrVector("fisk")); 353 Handle<Object> i = FACTORY->NewStringFromAscii(CStrVector("fisk"));
351 Handle<Object> u = Factory::NewNumber(1.12344); 354 Handle<Object> u = FACTORY->NewNumber(1.12344);
352 355
353 h1 = GlobalHandles::Create(*i); 356 h1 = global_handles->Create(*i);
354 h2 = GlobalHandles::Create(*u); 357 h2 = global_handles->Create(*u);
355 } 358 }
356 359
357 GlobalHandles::MakeWeak(h2.location(), 360 global_handles->MakeWeak(h2.location(),
358 reinterpret_cast<void*>(1234), 361 reinterpret_cast<void*>(1234),
359 &TestWeakGlobalHandleCallback); 362 &TestWeakGlobalHandleCallback);
360 363
361 // Scavenge treats weak pointers as normal roots. 364 // Scavenge treats weak pointers as normal roots.
362 Heap::PerformScavenge(); 365 HEAP->PerformScavenge();
363 366
364 CHECK((*h1)->IsString()); 367 CHECK((*h1)->IsString());
365 CHECK((*h2)->IsHeapNumber()); 368 CHECK((*h2)->IsHeapNumber());
366 369
367 CHECK(!WeakPointerCleared); 370 CHECK(!WeakPointerCleared);
368 CHECK(!GlobalHandles::IsNearDeath(h2.location())); 371 CHECK(!global_handles->IsNearDeath(h2.location()));
369 CHECK(!GlobalHandles::IsNearDeath(h1.location())); 372 CHECK(!global_handles->IsNearDeath(h1.location()));
370 373
371 GlobalHandles::Destroy(h1.location()); 374 global_handles->Destroy(h1.location());
372 GlobalHandles::Destroy(h2.location()); 375 global_handles->Destroy(h2.location());
373 } 376 }
374 377
375 378
376 TEST(WeakGlobalHandlesMark) { 379 TEST(WeakGlobalHandlesMark) {
380 GlobalHandles* global_handles = Isolate::Current()->global_handles();
377 InitializeVM(); 381 InitializeVM();
378 382
379 WeakPointerCleared = false; 383 WeakPointerCleared = false;
380 384
381 Handle<Object> h1; 385 Handle<Object> h1;
382 Handle<Object> h2; 386 Handle<Object> h2;
383 387
384 { 388 {
385 HandleScope scope; 389 HandleScope scope;
386 390
387 Handle<Object> i = Factory::NewStringFromAscii(CStrVector("fisk")); 391 Handle<Object> i = FACTORY->NewStringFromAscii(CStrVector("fisk"));
388 Handle<Object> u = Factory::NewNumber(1.12344); 392 Handle<Object> u = FACTORY->NewNumber(1.12344);
389 393
390 h1 = GlobalHandles::Create(*i); 394 h1 = global_handles->Create(*i);
391 h2 = GlobalHandles::Create(*u); 395 h2 = global_handles->Create(*u);
392 } 396 }
393 397
394 Heap::CollectGarbage(OLD_POINTER_SPACE); 398 HEAP->CollectGarbage(OLD_POINTER_SPACE);
395 Heap::CollectGarbage(NEW_SPACE); 399 HEAP->CollectGarbage(NEW_SPACE);
396 // Make sure the object is promoted. 400 // Make sure the object is promoted.
397 401
398 GlobalHandles::MakeWeak(h2.location(), 402 global_handles->MakeWeak(h2.location(),
399 reinterpret_cast<void*>(1234), 403 reinterpret_cast<void*>(1234),
400 &TestWeakGlobalHandleCallback); 404 &TestWeakGlobalHandleCallback);
401 CHECK(!GlobalHandles::IsNearDeath(h1.location())); 405 CHECK(!GlobalHandles::IsNearDeath(h1.location()));
402 CHECK(!GlobalHandles::IsNearDeath(h2.location())); 406 CHECK(!GlobalHandles::IsNearDeath(h2.location()));
403 407
404 Heap::CollectGarbage(OLD_POINTER_SPACE); 408 HEAP->CollectGarbage(OLD_POINTER_SPACE);
405 409
406 CHECK((*h1)->IsString()); 410 CHECK((*h1)->IsString());
407 411
408 CHECK(WeakPointerCleared); 412 CHECK(WeakPointerCleared);
409 CHECK(!GlobalHandles::IsNearDeath(h1.location())); 413 CHECK(!GlobalHandles::IsNearDeath(h1.location()));
410 414
411 GlobalHandles::Destroy(h1.location()); 415 global_handles->Destroy(h1.location());
412 } 416 }
413 417
414 TEST(DeleteWeakGlobalHandle) { 418 TEST(DeleteWeakGlobalHandle) {
419 GlobalHandles* global_handles = Isolate::Current()->global_handles();
415 InitializeVM(); 420 InitializeVM();
416 421
417 WeakPointerCleared = false; 422 WeakPointerCleared = false;
418 423
419 Handle<Object> h; 424 Handle<Object> h;
420 425
421 { 426 {
422 HandleScope scope; 427 HandleScope scope;
423 428
424 Handle<Object> i = Factory::NewStringFromAscii(CStrVector("fisk")); 429 Handle<Object> i = FACTORY->NewStringFromAscii(CStrVector("fisk"));
425 h = GlobalHandles::Create(*i); 430 h = global_handles->Create(*i);
426 } 431 }
427 432
428 GlobalHandles::MakeWeak(h.location(), 433 global_handles->MakeWeak(h.location(),
429 reinterpret_cast<void*>(1234), 434 reinterpret_cast<void*>(1234),
430 &TestWeakGlobalHandleCallback); 435 &TestWeakGlobalHandleCallback);
431 436
432 // Scanvenge does not recognize weak reference. 437 // Scanvenge does not recognize weak reference.
433 Heap::PerformScavenge(); 438 HEAP->PerformScavenge();
434 439
435 CHECK(!WeakPointerCleared); 440 CHECK(!WeakPointerCleared);
436 441
437 // Mark-compact treats weak reference properly. 442 // Mark-compact treats weak reference properly.
438 Heap::CollectGarbage(OLD_POINTER_SPACE); 443 HEAP->CollectGarbage(OLD_POINTER_SPACE);
439 444
440 CHECK(WeakPointerCleared); 445 CHECK(WeakPointerCleared);
441 } 446 }
442 447
443 static const char* not_so_random_string_table[] = { 448 static const char* not_so_random_string_table[] = {
444 "abstract", 449 "abstract",
445 "boolean", 450 "boolean",
446 "break", 451 "break",
447 "byte", 452 "byte",
448 "case", 453 "case",
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
500 "volatile", 505 "volatile",
501 "while", 506 "while",
502 "with", 507 "with",
503 0 508 0
504 }; 509 };
505 510
506 511
507 static void CheckSymbols(const char** strings) { 512 static void CheckSymbols(const char** strings) {
508 for (const char* string = *strings; *strings != 0; string = *strings++) { 513 for (const char* string = *strings; *strings != 0; string = *strings++) {
509 Object* a; 514 Object* a;
510 MaybeObject* maybe_a = Heap::LookupAsciiSymbol(string); 515 MaybeObject* maybe_a = HEAP->LookupAsciiSymbol(string);
511 // LookupAsciiSymbol may return a failure if a GC is needed. 516 // LookupAsciiSymbol may return a failure if a GC is needed.
512 if (!maybe_a->ToObject(&a)) continue; 517 if (!maybe_a->ToObject(&a)) continue;
513 CHECK(a->IsSymbol()); 518 CHECK(a->IsSymbol());
514 Object* b; 519 Object* b;
515 MaybeObject *maybe_b = Heap::LookupAsciiSymbol(string); 520 MaybeObject* maybe_b = HEAP->LookupAsciiSymbol(string);
516 if (!maybe_b->ToObject(&b)) continue; 521 if (!maybe_b->ToObject(&b)) continue;
517 CHECK_EQ(b, a); 522 CHECK_EQ(b, a);
518 CHECK(String::cast(b)->IsEqualTo(CStrVector(string))); 523 CHECK(String::cast(b)->IsEqualTo(CStrVector(string)));
519 } 524 }
520 } 525 }
521 526
522 527
523 TEST(SymbolTable) { 528 TEST(SymbolTable) {
524 InitializeVM(); 529 InitializeVM();
525 530
526 CheckSymbols(not_so_random_string_table); 531 CheckSymbols(not_so_random_string_table);
527 CheckSymbols(not_so_random_string_table); 532 CheckSymbols(not_so_random_string_table);
528 } 533 }
529 534
530 535
531 TEST(FunctionAllocation) { 536 TEST(FunctionAllocation) {
532 InitializeVM(); 537 InitializeVM();
533 538
534 v8::HandleScope sc; 539 v8::HandleScope sc;
535 Handle<String> name = Factory::LookupAsciiSymbol("theFunction"); 540 Handle<String> name = FACTORY->LookupAsciiSymbol("theFunction");
536 Handle<JSFunction> function = 541 Handle<JSFunction> function =
537 Factory::NewFunction(name, Factory::undefined_value()); 542 FACTORY->NewFunction(name, FACTORY->undefined_value());
538 Handle<Map> initial_map = 543 Handle<Map> initial_map =
539 Factory::NewMap(JS_OBJECT_TYPE, JSObject::kHeaderSize); 544 FACTORY->NewMap(JS_OBJECT_TYPE, JSObject::kHeaderSize);
540 function->set_initial_map(*initial_map); 545 function->set_initial_map(*initial_map);
541 546
542 Handle<String> prop_name = Factory::LookupAsciiSymbol("theSlot"); 547 Handle<String> prop_name = FACTORY->LookupAsciiSymbol("theSlot");
543 Handle<JSObject> obj = Factory::NewJSObject(function); 548 Handle<JSObject> obj = FACTORY->NewJSObject(function);
544 obj->SetProperty( 549 obj->SetProperty(
545 *prop_name, Smi::FromInt(23), NONE, kNonStrictMode)->ToObjectChecked(); 550 *prop_name, Smi::FromInt(23), NONE, kNonStrictMode)->ToObjectChecked();
546 CHECK_EQ(Smi::FromInt(23), obj->GetProperty(*prop_name)); 551 CHECK_EQ(Smi::FromInt(23), obj->GetProperty(*prop_name));
547 // Check that we can add properties to function objects. 552 // Check that we can add properties to function objects.
548 function->SetProperty( 553 function->SetProperty(
549 *prop_name, Smi::FromInt(24), NONE, kNonStrictMode)->ToObjectChecked(); 554 *prop_name, Smi::FromInt(24), NONE, kNonStrictMode)->ToObjectChecked();
550 CHECK_EQ(Smi::FromInt(24), function->GetProperty(*prop_name)); 555 CHECK_EQ(Smi::FromInt(24), function->GetProperty(*prop_name));
551 } 556 }
552 557
553 558
554 TEST(ObjectProperties) { 559 TEST(ObjectProperties) {
555 InitializeVM(); 560 InitializeVM();
556 561
557 v8::HandleScope sc; 562 v8::HandleScope sc;
558 String* object_symbol = String::cast(Heap::Object_symbol()); 563 String* object_symbol = String::cast(HEAP->Object_symbol());
559 Object* raw_object = 564 Object* raw_object = Isolate::Current()->context()->global()->
560 Top::context()->global()->GetProperty(object_symbol)->ToObjectChecked(); 565 GetProperty(object_symbol)->ToObjectChecked();
561 JSFunction* object_function = JSFunction::cast(raw_object); 566 JSFunction* object_function = JSFunction::cast(raw_object);
562 Handle<JSFunction> constructor(object_function); 567 Handle<JSFunction> constructor(object_function);
563 Handle<JSObject> obj = Factory::NewJSObject(constructor); 568 Handle<JSObject> obj = FACTORY->NewJSObject(constructor);
564 Handle<String> first = Factory::LookupAsciiSymbol("first"); 569 Handle<String> first = FACTORY->LookupAsciiSymbol("first");
565 Handle<String> second = Factory::LookupAsciiSymbol("second"); 570 Handle<String> second = FACTORY->LookupAsciiSymbol("second");
566 571
567 // check for empty 572 // check for empty
568 CHECK(!obj->HasLocalProperty(*first)); 573 CHECK(!obj->HasLocalProperty(*first));
569 574
570 // add first 575 // add first
571 obj->SetProperty( 576 obj->SetProperty(
572 *first, Smi::FromInt(1), NONE, kNonStrictMode)->ToObjectChecked(); 577 *first, Smi::FromInt(1), NONE, kNonStrictMode)->ToObjectChecked();
573 CHECK(obj->HasLocalProperty(*first)); 578 CHECK(obj->HasLocalProperty(*first));
574 579
575 // delete first 580 // delete first
(...skipping 25 matching lines...) Expand all
601 606
602 // delete second and then first 607 // delete second and then first
603 CHECK(obj->DeleteProperty(*second, JSObject::NORMAL_DELETION)); 608 CHECK(obj->DeleteProperty(*second, JSObject::NORMAL_DELETION));
604 CHECK(obj->HasLocalProperty(*first)); 609 CHECK(obj->HasLocalProperty(*first));
605 CHECK(obj->DeleteProperty(*first, JSObject::NORMAL_DELETION)); 610 CHECK(obj->DeleteProperty(*first, JSObject::NORMAL_DELETION));
606 CHECK(!obj->HasLocalProperty(*first)); 611 CHECK(!obj->HasLocalProperty(*first));
607 CHECK(!obj->HasLocalProperty(*second)); 612 CHECK(!obj->HasLocalProperty(*second));
608 613
609 // check string and symbol match 614 // check string and symbol match
610 static const char* string1 = "fisk"; 615 static const char* string1 = "fisk";
611 Handle<String> s1 = Factory::NewStringFromAscii(CStrVector(string1)); 616 Handle<String> s1 = FACTORY->NewStringFromAscii(CStrVector(string1));
612 obj->SetProperty( 617 obj->SetProperty(
613 *s1, Smi::FromInt(1), NONE, kNonStrictMode)->ToObjectChecked(); 618 *s1, Smi::FromInt(1), NONE, kNonStrictMode)->ToObjectChecked();
614 Handle<String> s1_symbol = Factory::LookupAsciiSymbol(string1); 619 Handle<String> s1_symbol = FACTORY->LookupAsciiSymbol(string1);
615 CHECK(obj->HasLocalProperty(*s1_symbol)); 620 CHECK(obj->HasLocalProperty(*s1_symbol));
616 621
617 // check symbol and string match 622 // check symbol and string match
618 static const char* string2 = "fugl"; 623 static const char* string2 = "fugl";
619 Handle<String> s2_symbol = Factory::LookupAsciiSymbol(string2); 624 Handle<String> s2_symbol = FACTORY->LookupAsciiSymbol(string2);
620 obj->SetProperty( 625 obj->SetProperty(
621 *s2_symbol, Smi::FromInt(1), NONE, kNonStrictMode)->ToObjectChecked(); 626 *s2_symbol, Smi::FromInt(1), NONE, kNonStrictMode)->ToObjectChecked();
622 Handle<String> s2 = Factory::NewStringFromAscii(CStrVector(string2)); 627 Handle<String> s2 = FACTORY->NewStringFromAscii(CStrVector(string2));
623 CHECK(obj->HasLocalProperty(*s2)); 628 CHECK(obj->HasLocalProperty(*s2));
624 } 629 }
625 630
626 631
627 TEST(JSObjectMaps) { 632 TEST(JSObjectMaps) {
628 InitializeVM(); 633 InitializeVM();
629 634
630 v8::HandleScope sc; 635 v8::HandleScope sc;
631 Handle<String> name = Factory::LookupAsciiSymbol("theFunction"); 636 Handle<String> name = FACTORY->LookupAsciiSymbol("theFunction");
632 Handle<JSFunction> function = 637 Handle<JSFunction> function =
633 Factory::NewFunction(name, Factory::undefined_value()); 638 FACTORY->NewFunction(name, FACTORY->undefined_value());
634 Handle<Map> initial_map = 639 Handle<Map> initial_map =
635 Factory::NewMap(JS_OBJECT_TYPE, JSObject::kHeaderSize); 640 FACTORY->NewMap(JS_OBJECT_TYPE, JSObject::kHeaderSize);
636 function->set_initial_map(*initial_map); 641 function->set_initial_map(*initial_map);
637 642
638 Handle<String> prop_name = Factory::LookupAsciiSymbol("theSlot"); 643 Handle<String> prop_name = FACTORY->LookupAsciiSymbol("theSlot");
639 Handle<JSObject> obj = Factory::NewJSObject(function); 644 Handle<JSObject> obj = FACTORY->NewJSObject(function);
640 645
641 // Set a propery 646 // Set a propery
642 obj->SetProperty( 647 obj->SetProperty(
643 *prop_name, Smi::FromInt(23), NONE, kNonStrictMode)->ToObjectChecked(); 648 *prop_name, Smi::FromInt(23), NONE, kNonStrictMode)->ToObjectChecked();
644 CHECK_EQ(Smi::FromInt(23), obj->GetProperty(*prop_name)); 649 CHECK_EQ(Smi::FromInt(23), obj->GetProperty(*prop_name));
645 650
646 // Check the map has changed 651 // Check the map has changed
647 CHECK(*initial_map != obj->map()); 652 CHECK(*initial_map != obj->map());
648 } 653 }
649 654
650 655
651 TEST(JSArray) { 656 TEST(JSArray) {
652 InitializeVM(); 657 InitializeVM();
653 658
654 v8::HandleScope sc; 659 v8::HandleScope sc;
655 Handle<String> name = Factory::LookupAsciiSymbol("Array"); 660 Handle<String> name = FACTORY->LookupAsciiSymbol("Array");
656 Object* raw_object = 661 Object* raw_object = Isolate::Current()->context()->global()->
657 Top::context()->global()->GetProperty(*name)->ToObjectChecked(); 662 GetProperty(*name)->ToObjectChecked();
658 Handle<JSFunction> function = Handle<JSFunction>( 663 Handle<JSFunction> function = Handle<JSFunction>(
659 JSFunction::cast(raw_object)); 664 JSFunction::cast(raw_object));
660 665
661 // Allocate the object. 666 // Allocate the object.
662 Handle<JSObject> object = Factory::NewJSObject(function); 667 Handle<JSObject> object = FACTORY->NewJSObject(function);
663 Handle<JSArray> array = Handle<JSArray>::cast(object); 668 Handle<JSArray> array = Handle<JSArray>::cast(object);
664 // We just initialized the VM, no heap allocation failure yet. 669 // We just initialized the VM, no heap allocation failure yet.
665 Object* ok = array->Initialize(0)->ToObjectChecked(); 670 Object* ok = array->Initialize(0)->ToObjectChecked();
666 671
667 // Set array length to 0. 672 // Set array length to 0.
668 ok = array->SetElementsLength(Smi::FromInt(0))->ToObjectChecked(); 673 ok = array->SetElementsLength(Smi::FromInt(0))->ToObjectChecked();
669 CHECK_EQ(Smi::FromInt(0), array->length()); 674 CHECK_EQ(Smi::FromInt(0), array->length());
670 CHECK(array->HasFastElements()); // Must be in fast mode. 675 CHECK(array->HasFastElements()); // Must be in fast mode.
671 676
672 // array[length] = name. 677 // array[length] = name.
673 ok = array->SetElement(0, *name, kNonStrictMode)->ToObjectChecked(); 678 ok = array->SetElement(0, *name, kNonStrictMode)->ToObjectChecked();
674 CHECK_EQ(Smi::FromInt(1), array->length()); 679 CHECK_EQ(Smi::FromInt(1), array->length());
675 CHECK_EQ(array->GetElement(0), *name); 680 CHECK_EQ(array->GetElement(0), *name);
676 681
677 // Set array length with larger than smi value. 682 // Set array length with larger than smi value.
678 Handle<Object> length = 683 Handle<Object> length =
679 Factory::NewNumberFromUint(static_cast<uint32_t>(Smi::kMaxValue) + 1); 684 FACTORY->NewNumberFromUint(static_cast<uint32_t>(Smi::kMaxValue) + 1);
680 ok = array->SetElementsLength(*length)->ToObjectChecked(); 685 ok = array->SetElementsLength(*length)->ToObjectChecked();
681 686
682 uint32_t int_length = 0; 687 uint32_t int_length = 0;
683 CHECK(length->ToArrayIndex(&int_length)); 688 CHECK(length->ToArrayIndex(&int_length));
684 CHECK_EQ(*length, array->length()); 689 CHECK_EQ(*length, array->length());
685 CHECK(array->HasDictionaryElements()); // Must be in slow mode. 690 CHECK(array->HasDictionaryElements()); // Must be in slow mode.
686 691
687 // array[length] = name. 692 // array[length] = name.
688 ok = array->SetElement(int_length, *name, kNonStrictMode)->ToObjectChecked(); 693 ok = array->SetElement(int_length, *name, kNonStrictMode)->ToObjectChecked();
689 uint32_t new_int_length = 0; 694 uint32_t new_int_length = 0;
690 CHECK(array->length()->ToArrayIndex(&new_int_length)); 695 CHECK(array->length()->ToArrayIndex(&new_int_length));
691 CHECK_EQ(static_cast<double>(int_length), new_int_length - 1); 696 CHECK_EQ(static_cast<double>(int_length), new_int_length - 1);
692 CHECK_EQ(array->GetElement(int_length), *name); 697 CHECK_EQ(array->GetElement(int_length), *name);
693 CHECK_EQ(array->GetElement(0), *name); 698 CHECK_EQ(array->GetElement(0), *name);
694 } 699 }
695 700
696 701
697 TEST(JSObjectCopy) { 702 TEST(JSObjectCopy) {
698 InitializeVM(); 703 InitializeVM();
699 704
700 v8::HandleScope sc; 705 v8::HandleScope sc;
701 String* object_symbol = String::cast(Heap::Object_symbol()); 706 String* object_symbol = String::cast(HEAP->Object_symbol());
702 Object* raw_object = 707 Object* raw_object = Isolate::Current()->context()->global()->
703 Top::context()->global()->GetProperty(object_symbol)->ToObjectChecked(); 708 GetProperty(object_symbol)->ToObjectChecked();
704 JSFunction* object_function = JSFunction::cast(raw_object); 709 JSFunction* object_function = JSFunction::cast(raw_object);
705 Handle<JSFunction> constructor(object_function); 710 Handle<JSFunction> constructor(object_function);
706 Handle<JSObject> obj = Factory::NewJSObject(constructor); 711 Handle<JSObject> obj = FACTORY->NewJSObject(constructor);
707 Handle<String> first = Factory::LookupAsciiSymbol("first"); 712 Handle<String> first = FACTORY->LookupAsciiSymbol("first");
708 Handle<String> second = Factory::LookupAsciiSymbol("second"); 713 Handle<String> second = FACTORY->LookupAsciiSymbol("second");
709 714
710 obj->SetProperty( 715 obj->SetProperty(
711 *first, Smi::FromInt(1), NONE, kNonStrictMode)->ToObjectChecked(); 716 *first, Smi::FromInt(1), NONE, kNonStrictMode)->ToObjectChecked();
712 obj->SetProperty( 717 obj->SetProperty(
713 *second, Smi::FromInt(2), NONE, kNonStrictMode)->ToObjectChecked(); 718 *second, Smi::FromInt(2), NONE, kNonStrictMode)->ToObjectChecked();
714 719
715 Object* ok = obj->SetElement(0, *first, kNonStrictMode)->ToObjectChecked(); 720 Object* ok = obj->SetElement(0, *first, kNonStrictMode)->ToObjectChecked();
716 721
717 ok = obj->SetElement(1, *second, kNonStrictMode)->ToObjectChecked(); 722 ok = obj->SetElement(1, *second, kNonStrictMode)->ToObjectChecked();
718 723
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
754 char* ascii = NewArray<char>(length + 1); 759 char* ascii = NewArray<char>(length + 1);
755 non_ascii[3 * length] = 0; 760 non_ascii[3 * length] = 0;
756 ascii[length] = 0; 761 ascii[length] = 0;
757 for (int i = 0; i < length; i++) { 762 for (int i = 0; i < length; i++) {
758 ascii[i] = 'a'; 763 ascii[i] = 'a';
759 non_ascii[3 * i] = chars[0]; 764 non_ascii[3 * i] = chars[0];
760 non_ascii[3 * i + 1] = chars[1]; 765 non_ascii[3 * i + 1] = chars[1];
761 non_ascii[3 * i + 2] = chars[2]; 766 non_ascii[3 * i + 2] = chars[2];
762 } 767 }
763 Handle<String> non_ascii_sym = 768 Handle<String> non_ascii_sym =
764 Factory::LookupSymbol(Vector<const char>(non_ascii, 3 * length)); 769 FACTORY->LookupSymbol(Vector<const char>(non_ascii, 3 * length));
765 CHECK_EQ(length, non_ascii_sym->length()); 770 CHECK_EQ(length, non_ascii_sym->length());
766 Handle<String> ascii_sym = 771 Handle<String> ascii_sym =
767 Factory::LookupSymbol(Vector<const char>(ascii, length)); 772 FACTORY->LookupSymbol(Vector<const char>(ascii, length));
768 CHECK_EQ(length, ascii_sym->length()); 773 CHECK_EQ(length, ascii_sym->length());
769 Handle<String> non_ascii_str = 774 Handle<String> non_ascii_str =
770 Factory::NewStringFromUtf8(Vector<const char>(non_ascii, 3 * length)); 775 FACTORY->NewStringFromUtf8(Vector<const char>(non_ascii, 3 * length));
771 non_ascii_str->Hash(); 776 non_ascii_str->Hash();
772 CHECK_EQ(length, non_ascii_str->length()); 777 CHECK_EQ(length, non_ascii_str->length());
773 Handle<String> ascii_str = 778 Handle<String> ascii_str =
774 Factory::NewStringFromUtf8(Vector<const char>(ascii, length)); 779 FACTORY->NewStringFromUtf8(Vector<const char>(ascii, length));
775 ascii_str->Hash(); 780 ascii_str->Hash();
776 CHECK_EQ(length, ascii_str->length()); 781 CHECK_EQ(length, ascii_str->length());
777 DeleteArray(non_ascii); 782 DeleteArray(non_ascii);
778 DeleteArray(ascii); 783 DeleteArray(ascii);
779 } 784 }
780 } 785 }
781 786
782 787
783 static int ObjectsFoundInHeap(Handle<Object> objs[], int size) { 788 static int ObjectsFoundInHeap(Handle<Object> objs[], int size) {
784 // Count the number of objects found in the heap. 789 // Count the number of objects found in the heap.
(...skipping 13 matching lines...) Expand all
798 TEST(Iteration) { 803 TEST(Iteration) {
799 InitializeVM(); 804 InitializeVM();
800 v8::HandleScope scope; 805 v8::HandleScope scope;
801 806
802 // Array of objects to scan haep for. 807 // Array of objects to scan haep for.
803 const int objs_count = 6; 808 const int objs_count = 6;
804 Handle<Object> objs[objs_count]; 809 Handle<Object> objs[objs_count];
805 int next_objs_index = 0; 810 int next_objs_index = 0;
806 811
807 // Allocate a JS array to OLD_POINTER_SPACE and NEW_SPACE 812 // Allocate a JS array to OLD_POINTER_SPACE and NEW_SPACE
808 objs[next_objs_index++] = Factory::NewJSArray(10); 813 objs[next_objs_index++] = FACTORY->NewJSArray(10);
809 objs[next_objs_index++] = Factory::NewJSArray(10, TENURED); 814 objs[next_objs_index++] = FACTORY->NewJSArray(10, TENURED);
810 815
811 // Allocate a small string to OLD_DATA_SPACE and NEW_SPACE 816 // Allocate a small string to OLD_DATA_SPACE and NEW_SPACE
812 objs[next_objs_index++] = 817 objs[next_objs_index++] =
813 Factory::NewStringFromAscii(CStrVector("abcdefghij")); 818 FACTORY->NewStringFromAscii(CStrVector("abcdefghij"));
814 objs[next_objs_index++] = 819 objs[next_objs_index++] =
815 Factory::NewStringFromAscii(CStrVector("abcdefghij"), TENURED); 820 FACTORY->NewStringFromAscii(CStrVector("abcdefghij"), TENURED);
816 821
817 // Allocate a large string (for large object space). 822 // Allocate a large string (for large object space).
818 int large_size = Heap::MaxObjectSizeInPagedSpace() + 1; 823 int large_size = HEAP->MaxObjectSizeInPagedSpace() + 1;
819 char* str = new char[large_size]; 824 char* str = new char[large_size];
820 for (int i = 0; i < large_size - 1; ++i) str[i] = 'a'; 825 for (int i = 0; i < large_size - 1; ++i) str[i] = 'a';
821 str[large_size - 1] = '\0'; 826 str[large_size - 1] = '\0';
822 objs[next_objs_index++] = 827 objs[next_objs_index++] =
823 Factory::NewStringFromAscii(CStrVector(str), TENURED); 828 FACTORY->NewStringFromAscii(CStrVector(str), TENURED);
824 delete[] str; 829 delete[] str;
825 830
826 // Add a Map object to look for. 831 // Add a Map object to look for.
827 objs[next_objs_index++] = Handle<Map>(HeapObject::cast(*objs[0])->map()); 832 objs[next_objs_index++] = Handle<Map>(HeapObject::cast(*objs[0])->map());
828 833
829 CHECK_EQ(objs_count, next_objs_index); 834 CHECK_EQ(objs_count, next_objs_index);
830 CHECK_EQ(objs_count, ObjectsFoundInHeap(objs, objs_count)); 835 CHECK_EQ(objs_count, ObjectsFoundInHeap(objs, objs_count));
831 } 836 }
832 837
833 838
834 TEST(LargeObjectSpaceContains) { 839 TEST(LargeObjectSpaceContains) {
835 InitializeVM(); 840 InitializeVM();
836 841
837 Heap::CollectGarbage(NEW_SPACE); 842 HEAP->CollectGarbage(NEW_SPACE);
838 843
839 Address current_top = Heap::new_space()->top(); 844 Address current_top = HEAP->new_space()->top();
840 Page* page = Page::FromAddress(current_top); 845 Page* page = Page::FromAddress(current_top);
841 Address current_page = page->address(); 846 Address current_page = page->address();
842 Address next_page = current_page + Page::kPageSize; 847 Address next_page = current_page + Page::kPageSize;
843 int bytes_to_page = static_cast<int>(next_page - current_top); 848 int bytes_to_page = static_cast<int>(next_page - current_top);
844 if (bytes_to_page <= FixedArray::kHeaderSize) { 849 if (bytes_to_page <= FixedArray::kHeaderSize) {
845 // Alas, need to cross another page to be able to 850 // Alas, need to cross another page to be able to
846 // put desired value. 851 // put desired value.
847 next_page += Page::kPageSize; 852 next_page += Page::kPageSize;
848 bytes_to_page = static_cast<int>(next_page - current_top); 853 bytes_to_page = static_cast<int>(next_page - current_top);
849 } 854 }
850 CHECK(bytes_to_page > FixedArray::kHeaderSize); 855 CHECK(bytes_to_page > FixedArray::kHeaderSize);
851 856
852 intptr_t* flags_ptr = &Page::FromAddress(next_page)->flags_; 857 intptr_t* flags_ptr = &Page::FromAddress(next_page)->flags_;
853 Address flags_addr = reinterpret_cast<Address>(flags_ptr); 858 Address flags_addr = reinterpret_cast<Address>(flags_ptr);
854 859
855 int bytes_to_allocate = 860 int bytes_to_allocate =
856 static_cast<int>(flags_addr - current_top) + kPointerSize; 861 static_cast<int>(flags_addr - current_top) + kPointerSize;
857 862
858 int n_elements = (bytes_to_allocate - FixedArray::kHeaderSize) / 863 int n_elements = (bytes_to_allocate - FixedArray::kHeaderSize) /
859 kPointerSize; 864 kPointerSize;
860 CHECK_EQ(bytes_to_allocate, FixedArray::SizeFor(n_elements)); 865 CHECK_EQ(bytes_to_allocate, FixedArray::SizeFor(n_elements));
861 FixedArray* array = FixedArray::cast( 866 FixedArray* array = FixedArray::cast(
862 Heap::AllocateFixedArray(n_elements)->ToObjectChecked()); 867 HEAP->AllocateFixedArray(n_elements)->ToObjectChecked());
863 868
864 int index = n_elements - 1; 869 int index = n_elements - 1;
865 CHECK_EQ(flags_ptr, 870 CHECK_EQ(flags_ptr,
866 HeapObject::RawField(array, FixedArray::OffsetOfElementAt(index))); 871 HeapObject::RawField(array, FixedArray::OffsetOfElementAt(index)));
867 array->set(index, Smi::FromInt(0)); 872 array->set(index, Smi::FromInt(0));
868 // This chould have turned next page into LargeObjectPage: 873 // This chould have turned next page into LargeObjectPage:
869 // CHECK(Page::FromAddress(next_page)->IsLargeObjectPage()); 874 // CHECK(Page::FromAddress(next_page)->IsLargeObjectPage());
870 875
871 HeapObject* addr = HeapObject::FromAddress(next_page + 2 * kPointerSize); 876 HeapObject* addr = HeapObject::FromAddress(next_page + 2 * kPointerSize);
872 CHECK(Heap::new_space()->Contains(addr)); 877 CHECK(HEAP->new_space()->Contains(addr));
873 CHECK(!Heap::lo_space()->Contains(addr)); 878 CHECK(!HEAP->lo_space()->Contains(addr));
874 } 879 }
875 880
876 881
877 TEST(EmptyHandleEscapeFrom) { 882 TEST(EmptyHandleEscapeFrom) {
878 InitializeVM(); 883 InitializeVM();
879 884
880 v8::HandleScope scope; 885 v8::HandleScope scope;
881 Handle<JSObject> runaway; 886 Handle<JSObject> runaway;
882 887
883 { 888 {
(...skipping 10 matching lines...) Expand all
894 return (size - FixedArray::kHeaderSize) / kPointerSize; 899 return (size - FixedArray::kHeaderSize) / kPointerSize;
895 } 900 }
896 901
897 902
898 TEST(Regression39128) { 903 TEST(Regression39128) {
899 // Test case for crbug.com/39128. 904 // Test case for crbug.com/39128.
900 InitializeVM(); 905 InitializeVM();
901 906
902 // Increase the chance of 'bump-the-pointer' allocation in old space. 907 // Increase the chance of 'bump-the-pointer' allocation in old space.
903 bool force_compaction = true; 908 bool force_compaction = true;
904 Heap::CollectAllGarbage(force_compaction); 909 HEAP->CollectAllGarbage(force_compaction);
905 910
906 v8::HandleScope scope; 911 v8::HandleScope scope;
907 912
908 // The plan: create JSObject which references objects in new space. 913 // The plan: create JSObject which references objects in new space.
909 // Then clone this object (forcing it to go into old space) and check 914 // Then clone this object (forcing it to go into old space) and check
910 // that region dirty marks are updated correctly. 915 // that region dirty marks are updated correctly.
911 916
912 // Step 1: prepare a map for the object. We add 1 inobject property to it. 917 // Step 1: prepare a map for the object. We add 1 inobject property to it.
913 Handle<JSFunction> object_ctor(Top::global_context()->object_function()); 918 Handle<JSFunction> object_ctor(
919 Isolate::Current()->global_context()->object_function());
914 CHECK(object_ctor->has_initial_map()); 920 CHECK(object_ctor->has_initial_map());
915 Handle<Map> object_map(object_ctor->initial_map()); 921 Handle<Map> object_map(object_ctor->initial_map());
916 // Create a map with single inobject property. 922 // Create a map with single inobject property.
917 Handle<Map> my_map = Factory::CopyMap(object_map, 1); 923 Handle<Map> my_map = FACTORY->CopyMap(object_map, 1);
918 int n_properties = my_map->inobject_properties(); 924 int n_properties = my_map->inobject_properties();
919 CHECK_GT(n_properties, 0); 925 CHECK_GT(n_properties, 0);
920 926
921 int object_size = my_map->instance_size(); 927 int object_size = my_map->instance_size();
922 928
923 // Step 2: allocate a lot of objects so to almost fill new space: we need 929 // Step 2: allocate a lot of objects so to almost fill new space: we need
924 // just enough room to allocate JSObject and thus fill the newspace. 930 // just enough room to allocate JSObject and thus fill the newspace.
925 931
926 int allocation_amount = Min(FixedArray::kMaxSize, 932 int allocation_amount = Min(FixedArray::kMaxSize,
927 Heap::MaxObjectSizeInNewSpace()); 933 HEAP->MaxObjectSizeInNewSpace());
928 int allocation_len = LenFromSize(allocation_amount); 934 int allocation_len = LenFromSize(allocation_amount);
929 NewSpace* new_space = Heap::new_space(); 935 NewSpace* new_space = HEAP->new_space();
930 Address* top_addr = new_space->allocation_top_address(); 936 Address* top_addr = new_space->allocation_top_address();
931 Address* limit_addr = new_space->allocation_limit_address(); 937 Address* limit_addr = new_space->allocation_limit_address();
932 while ((*limit_addr - *top_addr) > allocation_amount) { 938 while ((*limit_addr - *top_addr) > allocation_amount) {
933 CHECK(!Heap::always_allocate()); 939 CHECK(!HEAP->always_allocate());
934 Object* array = 940 Object* array = HEAP->AllocateFixedArray(allocation_len)->ToObjectChecked();
935 Heap::AllocateFixedArray(allocation_len)->ToObjectChecked(); 941 CHECK(!array->IsFailure());
936 CHECK(new_space->Contains(array)); 942 CHECK(new_space->Contains(array));
937 } 943 }
938 944
939 // Step 3: now allocate fixed array and JSObject to fill the whole new space. 945 // Step 3: now allocate fixed array and JSObject to fill the whole new space.
940 int to_fill = static_cast<int>(*limit_addr - *top_addr - object_size); 946 int to_fill = static_cast<int>(*limit_addr - *top_addr - object_size);
941 int fixed_array_len = LenFromSize(to_fill); 947 int fixed_array_len = LenFromSize(to_fill);
942 CHECK(fixed_array_len < FixedArray::kMaxLength); 948 CHECK(fixed_array_len < FixedArray::kMaxLength);
943 949
944 CHECK(!Heap::always_allocate()); 950 CHECK(!HEAP->always_allocate());
945 Object* array = 951 Object* array = HEAP->AllocateFixedArray(fixed_array_len)->ToObjectChecked();
946 Heap::AllocateFixedArray(fixed_array_len)->ToObjectChecked(); 952 CHECK(!array->IsFailure());
947 CHECK(new_space->Contains(array)); 953 CHECK(new_space->Contains(array));
948 954
949 Object* object = Heap::AllocateJSObjectFromMap(*my_map)->ToObjectChecked(); 955 Object* object = HEAP->AllocateJSObjectFromMap(*my_map)->ToObjectChecked();
950 CHECK(new_space->Contains(object)); 956 CHECK(new_space->Contains(object));
951 JSObject* jsobject = JSObject::cast(object); 957 JSObject* jsobject = JSObject::cast(object);
952 CHECK_EQ(0, FixedArray::cast(jsobject->elements())->length()); 958 CHECK_EQ(0, FixedArray::cast(jsobject->elements())->length());
953 CHECK_EQ(0, jsobject->properties()->length()); 959 CHECK_EQ(0, jsobject->properties()->length());
954 // Create a reference to object in new space in jsobject. 960 // Create a reference to object in new space in jsobject.
955 jsobject->FastPropertyAtPut(-1, array); 961 jsobject->FastPropertyAtPut(-1, array);
956 962
957 CHECK_EQ(0, static_cast<int>(*limit_addr - *top_addr)); 963 CHECK_EQ(0, static_cast<int>(*limit_addr - *top_addr));
958 964
959 // Step 4: clone jsobject, but force always allocate first to create a clone 965 // Step 4: clone jsobject, but force always allocate first to create a clone
960 // in old pointer space. 966 // in old pointer space.
961 Address old_pointer_space_top = Heap::old_pointer_space()->top(); 967 Address old_pointer_space_top = HEAP->old_pointer_space()->top();
962 AlwaysAllocateScope aa_scope; 968 AlwaysAllocateScope aa_scope;
963 Object* clone_obj = Heap::CopyJSObject(jsobject)->ToObjectChecked(); 969 Object* clone_obj = HEAP->CopyJSObject(jsobject)->ToObjectChecked();
964 JSObject* clone = JSObject::cast(clone_obj); 970 JSObject* clone = JSObject::cast(clone_obj);
965 if (clone->address() != old_pointer_space_top) { 971 if (clone->address() != old_pointer_space_top) {
966 // Alas, got allocated from free list, we cannot do checks. 972 // Alas, got allocated from free list, we cannot do checks.
967 return; 973 return;
968 } 974 }
969 CHECK(Heap::old_pointer_space()->Contains(clone->address())); 975 CHECK(HEAP->old_pointer_space()->Contains(clone->address()));
970 976
971 // Step 5: verify validity of region dirty marks. 977 // Step 5: verify validity of region dirty marks.
972 Address clone_addr = clone->address(); 978 Address clone_addr = clone->address();
973 Page* page = Page::FromAddress(clone_addr); 979 Page* page = Page::FromAddress(clone_addr);
974 // Check that region covering inobject property 1 is marked dirty. 980 // Check that region covering inobject property 1 is marked dirty.
975 CHECK(page->IsRegionDirty(clone_addr + (object_size - kPointerSize))); 981 CHECK(page->IsRegionDirty(clone_addr + (object_size - kPointerSize)));
976 } 982 }
977 983
978 984
979 TEST(TestCodeFlushing) { 985 TEST(TestCodeFlushing) {
980 i::FLAG_allow_natives_syntax = true; 986 i::FLAG_allow_natives_syntax = true;
981 // If we do not flush code this test is invalid. 987 // If we do not flush code this test is invalid.
982 if (!FLAG_flush_code) return; 988 if (!FLAG_flush_code) return;
983 InitializeVM(); 989 InitializeVM();
984 v8::HandleScope scope; 990 v8::HandleScope scope;
985 const char* source = "function foo() {" 991 const char* source = "function foo() {"
986 " var x = 42;" 992 " var x = 42;"
987 " var y = 42;" 993 " var y = 42;"
988 " var z = x + y;" 994 " var z = x + y;"
989 "};" 995 "};"
990 "foo()"; 996 "foo()";
991 Handle<String> foo_name = Factory::LookupAsciiSymbol("foo"); 997 Handle<String> foo_name = FACTORY->LookupAsciiSymbol("foo");
992 998
993 // This compile will add the code to the compilation cache. 999 // This compile will add the code to the compilation cache.
994 { v8::HandleScope scope; 1000 { v8::HandleScope scope;
995 CompileRun(source); 1001 CompileRun(source);
996 } 1002 }
997 1003
998 // Check function is compiled. 1004 // Check function is compiled.
999 Object* func_value = 1005 Object* func_value = Isolate::Current()->context()->global()->
1000 Top::context()->global()->GetProperty(*foo_name)->ToObjectChecked(); 1006 GetProperty(*foo_name)->ToObjectChecked();
1001 CHECK(func_value->IsJSFunction()); 1007 CHECK(func_value->IsJSFunction());
1002 Handle<JSFunction> function(JSFunction::cast(func_value)); 1008 Handle<JSFunction> function(JSFunction::cast(func_value));
1003 CHECK(function->shared()->is_compiled()); 1009 CHECK(function->shared()->is_compiled());
1004 1010
1005 Heap::CollectAllGarbage(true); 1011 HEAP->CollectAllGarbage(true);
1006 Heap::CollectAllGarbage(true); 1012 HEAP->CollectAllGarbage(true);
1007 1013
1008 CHECK(function->shared()->is_compiled()); 1014 CHECK(function->shared()->is_compiled());
1009 1015
1010 Heap::CollectAllGarbage(true); 1016 HEAP->CollectAllGarbage(true);
1011 Heap::CollectAllGarbage(true); 1017 HEAP->CollectAllGarbage(true);
1012 Heap::CollectAllGarbage(true); 1018 HEAP->CollectAllGarbage(true);
1013 Heap::CollectAllGarbage(true); 1019 HEAP->CollectAllGarbage(true);
1014 Heap::CollectAllGarbage(true); 1020 HEAP->CollectAllGarbage(true);
1015 Heap::CollectAllGarbage(true); 1021 HEAP->CollectAllGarbage(true);
1016 1022
1017 // foo should no longer be in the compilation cache 1023 // foo should no longer be in the compilation cache
1018 CHECK(!function->shared()->is_compiled() || function->IsOptimized()); 1024 CHECK(!function->shared()->is_compiled() || function->IsOptimized());
1019 CHECK(!function->is_compiled() || function->IsOptimized()); 1025 CHECK(!function->is_compiled() || function->IsOptimized());
1020 // Call foo to get it recompiled. 1026 // Call foo to get it recompiled.
1021 CompileRun("foo()"); 1027 CompileRun("foo()");
1022 CHECK(function->shared()->is_compiled()); 1028 CHECK(function->shared()->is_compiled());
1023 CHECK(function->is_compiled()); 1029 CHECK(function->is_compiled());
1024 } 1030 }
1025 1031
1026 1032
1027 // Count the number of global contexts in the weak list of global contexts. 1033 // Count the number of global contexts in the weak list of global contexts.
1028 static int CountGlobalContexts() { 1034 static int CountGlobalContexts() {
1029 int count = 0; 1035 int count = 0;
1030 Object* object = Heap::global_contexts_list(); 1036 Object* object = HEAP->global_contexts_list();
1031 while (!object->IsUndefined()) { 1037 while (!object->IsUndefined()) {
1032 count++; 1038 count++;
1033 object = Context::cast(object)->get(Context::NEXT_CONTEXT_LINK); 1039 object = Context::cast(object)->get(Context::NEXT_CONTEXT_LINK);
1034 } 1040 }
1035 return count; 1041 return count;
1036 } 1042 }
1037 1043
1038 1044
1039 // Count the number of user functions in the weak list of optimized 1045 // Count the number of user functions in the weak list of optimized
1040 // functions attached to a global context. 1046 // functions attached to a global context.
1041 static int CountOptimizedUserFunctions(v8::Handle<v8::Context> context) { 1047 static int CountOptimizedUserFunctions(v8::Handle<v8::Context> context) {
1042 int count = 0; 1048 int count = 0;
1043 Handle<Context> icontext = v8::Utils::OpenHandle(*context); 1049 Handle<Context> icontext = v8::Utils::OpenHandle(*context);
1044 Object* object = icontext->get(Context::OPTIMIZED_FUNCTIONS_LIST); 1050 Object* object = icontext->get(Context::OPTIMIZED_FUNCTIONS_LIST);
1045 while (object->IsJSFunction() && !JSFunction::cast(object)->IsBuiltin()) { 1051 while (object->IsJSFunction() && !JSFunction::cast(object)->IsBuiltin()) {
1046 count++; 1052 count++;
1047 object = JSFunction::cast(object)->next_function_link(); 1053 object = JSFunction::cast(object)->next_function_link();
1048 } 1054 }
1049 return count; 1055 return count;
1050 } 1056 }
1051 1057
1052 1058
1053 TEST(TestInternalWeakLists) { 1059 TEST(TestInternalWeakLists) {
1060 v8::V8::Initialize();
1061
1054 static const int kNumTestContexts = 10; 1062 static const int kNumTestContexts = 10;
1055 1063
1056 v8::HandleScope scope; 1064 v8::HandleScope scope;
1057 v8::Persistent<v8::Context> ctx[kNumTestContexts]; 1065 v8::Persistent<v8::Context> ctx[kNumTestContexts];
1058 1066
1059 CHECK_EQ(0, CountGlobalContexts()); 1067 CHECK_EQ(0, CountGlobalContexts());
1060 1068
1061 // Create a number of global contests which gets linked together. 1069 // Create a number of global contests which gets linked together.
1062 for (int i = 0; i < kNumTestContexts; i++) { 1070 for (int i = 0; i < kNumTestContexts; i++) {
1063 ctx[i] = v8::Context::New(); 1071 ctx[i] = v8::Context::New();
(...skipping 23 matching lines...) Expand all
1087 CompileRun("f4()"); 1095 CompileRun("f4()");
1088 CHECK_EQ(opt ? 4 : 0, CountOptimizedUserFunctions(ctx[i])); 1096 CHECK_EQ(opt ? 4 : 0, CountOptimizedUserFunctions(ctx[i]));
1089 CompileRun("f5()"); 1097 CompileRun("f5()");
1090 CHECK_EQ(opt ? 5 : 0, CountOptimizedUserFunctions(ctx[i])); 1098 CHECK_EQ(opt ? 5 : 0, CountOptimizedUserFunctions(ctx[i]));
1091 1099
1092 // Remove function f1, and 1100 // Remove function f1, and
1093 CompileRun("f1=null"); 1101 CompileRun("f1=null");
1094 1102
1095 // Scavenge treats these references as strong. 1103 // Scavenge treats these references as strong.
1096 for (int j = 0; j < 10; j++) { 1104 for (int j = 0; j < 10; j++) {
1097 Heap::PerformScavenge(); 1105 HEAP->PerformScavenge();
1098 CHECK_EQ(opt ? 5 : 0, CountOptimizedUserFunctions(ctx[i])); 1106 CHECK_EQ(opt ? 5 : 0, CountOptimizedUserFunctions(ctx[i]));
1099 } 1107 }
1100 1108
1101 // Mark compact handles the weak references. 1109 // Mark compact handles the weak references.
1102 Heap::CollectAllGarbage(true); 1110 HEAP->CollectAllGarbage(true);
1103 CHECK_EQ(opt ? 4 : 0, CountOptimizedUserFunctions(ctx[i])); 1111 CHECK_EQ(opt ? 4 : 0, CountOptimizedUserFunctions(ctx[i]));
1104 1112
1105 // Get rid of f3 and f5 in the same way. 1113 // Get rid of f3 and f5 in the same way.
1106 CompileRun("f3=null"); 1114 CompileRun("f3=null");
1107 for (int j = 0; j < 10; j++) { 1115 for (int j = 0; j < 10; j++) {
1108 Heap::PerformScavenge(); 1116 HEAP->PerformScavenge();
1109 CHECK_EQ(opt ? 4 : 0, CountOptimizedUserFunctions(ctx[i])); 1117 CHECK_EQ(opt ? 4 : 0, CountOptimizedUserFunctions(ctx[i]));
1110 } 1118 }
1111 Heap::CollectAllGarbage(true); 1119 HEAP->CollectAllGarbage(true);
1112 CHECK_EQ(opt ? 3 : 0, CountOptimizedUserFunctions(ctx[i])); 1120 CHECK_EQ(opt ? 3 : 0, CountOptimizedUserFunctions(ctx[i]));
1113 CompileRun("f5=null"); 1121 CompileRun("f5=null");
1114 for (int j = 0; j < 10; j++) { 1122 for (int j = 0; j < 10; j++) {
1115 Heap::PerformScavenge(); 1123 HEAP->PerformScavenge();
1116 CHECK_EQ(opt ? 3 : 0, CountOptimizedUserFunctions(ctx[i])); 1124 CHECK_EQ(opt ? 3 : 0, CountOptimizedUserFunctions(ctx[i]));
1117 } 1125 }
1118 Heap::CollectAllGarbage(true); 1126 HEAP->CollectAllGarbage(true);
1119 CHECK_EQ(opt ? 2 : 0, CountOptimizedUserFunctions(ctx[i])); 1127 CHECK_EQ(opt ? 2 : 0, CountOptimizedUserFunctions(ctx[i]));
1120 1128
1121 ctx[i]->Exit(); 1129 ctx[i]->Exit();
1122 } 1130 }
1123 1131
1124 // Force compilation cache cleanup. 1132 // Force compilation cache cleanup.
1125 Heap::CollectAllGarbage(true); 1133 HEAP->CollectAllGarbage(true);
1126 1134
1127 // Dispose the global contexts one by one. 1135 // Dispose the global contexts one by one.
1128 for (int i = 0; i < kNumTestContexts; i++) { 1136 for (int i = 0; i < kNumTestContexts; i++) {
1129 ctx[i].Dispose(); 1137 ctx[i].Dispose();
1130 ctx[i].Clear(); 1138 ctx[i].Clear();
1131 1139
1132 // Scavenge treats these references as strong. 1140 // Scavenge treats these references as strong.
1133 for (int j = 0; j < 10; j++) { 1141 for (int j = 0; j < 10; j++) {
1134 Heap::PerformScavenge(); 1142 HEAP->PerformScavenge();
1135 CHECK_EQ(kNumTestContexts - i, CountGlobalContexts()); 1143 CHECK_EQ(kNumTestContexts - i, CountGlobalContexts());
1136 } 1144 }
1137 1145
1138 // Mark compact handles the weak references. 1146 // Mark compact handles the weak references.
1139 Heap::CollectAllGarbage(true); 1147 HEAP->CollectAllGarbage(true);
1140 CHECK_EQ(kNumTestContexts - i - 1, CountGlobalContexts()); 1148 CHECK_EQ(kNumTestContexts - i - 1, CountGlobalContexts());
1141 } 1149 }
1142 1150
1143 CHECK_EQ(0, CountGlobalContexts()); 1151 CHECK_EQ(0, CountGlobalContexts());
1144 } 1152 }
1145 1153
1146 1154
1147 // Count the number of global contexts in the weak list of global contexts 1155 // Count the number of global contexts in the weak list of global contexts
1148 // causing a GC after the specified number of elements. 1156 // causing a GC after the specified number of elements.
1149 static int CountGlobalContextsWithGC(int n) { 1157 static int CountGlobalContextsWithGC(int n) {
1150 int count = 0; 1158 int count = 0;
1151 Handle<Object> object(Heap::global_contexts_list()); 1159 Handle<Object> object(HEAP->global_contexts_list());
1152 while (!object->IsUndefined()) { 1160 while (!object->IsUndefined()) {
1153 count++; 1161 count++;
1154 if (count == n) Heap::CollectAllGarbage(true); 1162 if (count == n) HEAP->CollectAllGarbage(true);
1155 object = 1163 object =
1156 Handle<Object>(Context::cast(*object)->get(Context::NEXT_CONTEXT_LINK)); 1164 Handle<Object>(Context::cast(*object)->get(Context::NEXT_CONTEXT_LINK));
1157 } 1165 }
1158 return count; 1166 return count;
1159 } 1167 }
1160 1168
1161 1169
1162 // Count the number of user functions in the weak list of optimized 1170 // Count the number of user functions in the weak list of optimized
1163 // functions attached to a global context causing a GC after the 1171 // functions attached to a global context causing a GC after the
1164 // specified number of elements. 1172 // specified number of elements.
1165 static int CountOptimizedUserFunctionsWithGC(v8::Handle<v8::Context> context, 1173 static int CountOptimizedUserFunctionsWithGC(v8::Handle<v8::Context> context,
1166 int n) { 1174 int n) {
1167 int count = 0; 1175 int count = 0;
1168 Handle<Context> icontext = v8::Utils::OpenHandle(*context); 1176 Handle<Context> icontext = v8::Utils::OpenHandle(*context);
1169 Handle<Object> object(icontext->get(Context::OPTIMIZED_FUNCTIONS_LIST)); 1177 Handle<Object> object(icontext->get(Context::OPTIMIZED_FUNCTIONS_LIST));
1170 while (object->IsJSFunction() && 1178 while (object->IsJSFunction() &&
1171 !Handle<JSFunction>::cast(object)->IsBuiltin()) { 1179 !Handle<JSFunction>::cast(object)->IsBuiltin()) {
1172 count++; 1180 count++;
1173 if (count == n) Heap::CollectAllGarbage(true); 1181 if (count == n) HEAP->CollectAllGarbage(true);
1174 object = Handle<Object>( 1182 object = Handle<Object>(
1175 Object::cast(JSFunction::cast(*object)->next_function_link())); 1183 Object::cast(JSFunction::cast(*object)->next_function_link()));
1176 } 1184 }
1177 return count; 1185 return count;
1178 } 1186 }
1179 1187
1180 1188
1181 TEST(TestInternalWeakListsTraverseWithGC) { 1189 TEST(TestInternalWeakListsTraverseWithGC) {
1190 v8::V8::Initialize();
1191
1182 static const int kNumTestContexts = 10; 1192 static const int kNumTestContexts = 10;
1183 1193
1184 v8::HandleScope scope; 1194 v8::HandleScope scope;
1185 v8::Persistent<v8::Context> ctx[kNumTestContexts]; 1195 v8::Persistent<v8::Context> ctx[kNumTestContexts];
1186 1196
1187 CHECK_EQ(0, CountGlobalContexts()); 1197 CHECK_EQ(0, CountGlobalContexts());
1188 1198
1189 // Create an number of contexts and check the length of the weak list both 1199 // Create an number of contexts and check the length of the weak list both
1190 // with and without GCs while iterating the list. 1200 // with and without GCs while iterating the list.
1191 for (int i = 0; i < kNumTestContexts; i++) { 1201 for (int i = 0; i < kNumTestContexts; i++) {
(...skipping 29 matching lines...) Expand all
1221 CompileRun("f5()"); 1231 CompileRun("f5()");
1222 CHECK_EQ(opt ? 5 : 0, CountOptimizedUserFunctions(ctx[0])); 1232 CHECK_EQ(opt ? 5 : 0, CountOptimizedUserFunctions(ctx[0]));
1223 CHECK_EQ(opt ? 5 : 0, CountOptimizedUserFunctionsWithGC(ctx[0], 4)); 1233 CHECK_EQ(opt ? 5 : 0, CountOptimizedUserFunctionsWithGC(ctx[0], 4));
1224 1234
1225 ctx[0]->Exit(); 1235 ctx[0]->Exit();
1226 } 1236 }
1227 1237
1228 1238
1229 TEST(TestSizeOfObjectsVsHeapIteratorPrecision) { 1239 TEST(TestSizeOfObjectsVsHeapIteratorPrecision) {
1230 InitializeVM(); 1240 InitializeVM();
1231 intptr_t size_of_objects_1 = Heap::SizeOfObjects(); 1241 intptr_t size_of_objects_1 = HEAP->SizeOfObjects();
1232 HeapIterator iterator(HeapIterator::kFilterFreeListNodes); 1242 HeapIterator iterator(HeapIterator::kFilterFreeListNodes);
1233 intptr_t size_of_objects_2 = 0; 1243 intptr_t size_of_objects_2 = 0;
1234 for (HeapObject* obj = iterator.next(); 1244 for (HeapObject* obj = iterator.next();
1235 obj != NULL; 1245 obj != NULL;
1236 obj = iterator.next()) { 1246 obj = iterator.next()) {
1237 size_of_objects_2 += obj->Size(); 1247 size_of_objects_2 += obj->Size();
1238 } 1248 }
1239 // Delta must be within 1% of the larger result. 1249 // Delta must be within 1% of the larger result.
1240 if (size_of_objects_1 > size_of_objects_2) { 1250 if (size_of_objects_1 > size_of_objects_2) {
1241 intptr_t delta = size_of_objects_1 - size_of_objects_2; 1251 intptr_t delta = size_of_objects_1 - size_of_objects_2;
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
1276 Object* a_; 1286 Object* a_;
1277 Object* b_; 1287 Object* b_;
1278 bool a_found_; 1288 bool a_found_;
1279 bool b_found_; 1289 bool b_found_;
1280 }; 1290 };
1281 1291
1282 TEST(HeapIteratorFilterUnreachable) { 1292 TEST(HeapIteratorFilterUnreachable) {
1283 InitializeVM(); 1293 InitializeVM();
1284 v8::HandleScope scope; 1294 v8::HandleScope scope;
1285 CompileRun("a = {}; b = {};"); 1295 CompileRun("a = {}; b = {};");
1286 v8::Handle<Object> a(Top::context()->global()->GetProperty( 1296 v8::Handle<Object> a(ISOLATE->context()->global()->GetProperty(
1287 *Factory::LookupAsciiSymbol("a"))->ToObjectChecked()); 1297 *FACTORY->LookupAsciiSymbol("a"))->ToObjectChecked());
1288 v8::Handle<Object> b(Top::context()->global()->GetProperty( 1298 v8::Handle<Object> b(ISOLATE->context()->global()->GetProperty(
1289 *Factory::LookupAsciiSymbol("b"))->ToObjectChecked()); 1299 *FACTORY->LookupAsciiSymbol("b"))->ToObjectChecked());
1290 CHECK_NE(*a, *b); 1300 CHECK_NE(*a, *b);
1291 { 1301 {
1292 HeapIteratorTestHelper helper(*a, *b); 1302 HeapIteratorTestHelper helper(*a, *b);
1293 helper.IterateHeap(HeapIterator::kFilterUnreachable); 1303 helper.IterateHeap(HeapIterator::kFilterUnreachable);
1294 CHECK(helper.a_found()); 1304 CHECK(helper.a_found());
1295 CHECK(helper.b_found()); 1305 CHECK(helper.b_found());
1296 } 1306 }
1297 CHECK(Top::context()->global()->DeleteProperty( 1307 CHECK(ISOLATE->context()->global()->DeleteProperty(
1298 *Factory::LookupAsciiSymbol("a"), JSObject::FORCE_DELETION)); 1308 *FACTORY->LookupAsciiSymbol("a"), JSObject::FORCE_DELETION));
1299 // We ensure that GC will not happen, so our raw pointer stays valid. 1309 // We ensure that GC will not happen, so our raw pointer stays valid.
1300 AssertNoAllocation no_alloc; 1310 AssertNoAllocation no_alloc;
1301 Object* a_saved = *a; 1311 Object* a_saved = *a;
1302 a.Clear(); 1312 a.Clear();
1303 // Verify that "a" object still resides in the heap... 1313 // Verify that "a" object still resides in the heap...
1304 { 1314 {
1305 HeapIteratorTestHelper helper(a_saved, *b); 1315 HeapIteratorTestHelper helper(a_saved, *b);
1306 helper.IterateHeap(HeapIterator::kNoFiltering); 1316 helper.IterateHeap(HeapIterator::kNoFiltering);
1307 CHECK(helper.a_found()); 1317 CHECK(helper.a_found());
1308 CHECK(helper.b_found()); 1318 CHECK(helper.b_found());
1309 } 1319 }
1310 // ...but is now unreachable. 1320 // ...but is now unreachable.
1311 { 1321 {
1312 HeapIteratorTestHelper helper(a_saved, *b); 1322 HeapIteratorTestHelper helper(a_saved, *b);
1313 helper.IterateHeap(HeapIterator::kFilterUnreachable); 1323 helper.IterateHeap(HeapIterator::kFilterUnreachable);
1314 CHECK(!helper.a_found()); 1324 CHECK(!helper.a_found());
1315 CHECK(helper.b_found()); 1325 CHECK(helper.b_found());
1316 } 1326 }
1317 } 1327 }
OLDNEW
« no previous file with comments | « test/cctest/test-func-name-inference.cc ('k') | test/cctest/test-heap-profiler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698