| OLD | NEW | 
|---|
| 1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 the V8 project authors. All rights reserved. | 
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without | 
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are | 
| 4 // met: | 4 // met: | 
| 5 // | 5 // | 
| 6 //     * Redistributions of source code must retain the above copyright | 6 //     * Redistributions of source code must retain the above copyright | 
| 7 //       notice, this list of conditions and the following disclaimer. | 7 //       notice, this list of conditions and the following disclaimer. | 
| 8 //     * Redistributions in binary form must reproduce the above | 8 //     * Redistributions in binary form must reproduce the above | 
| 9 //       copyright notice, this list of conditions and the following | 9 //       copyright notice, this list of conditions and the following | 
| 10 //       disclaimer in the documentation and/or other materials provided | 10 //       disclaimer in the documentation and/or other materials provided | 
| (...skipping 2388 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 2399         ++count; | 2399         ++count; | 
| 2400       } | 2400       } | 
| 2401     } | 2401     } | 
| 2402   } | 2402   } | 
| 2403   return count; | 2403   return count; | 
| 2404 } | 2404 } | 
| 2405 | 2405 | 
| 2406 | 2406 | 
| 2407 TEST(ArrayBufferSharedBackingStore) { | 2407 TEST(ArrayBufferSharedBackingStore) { | 
| 2408   LocalContext env; | 2408   LocalContext env; | 
| 2409   v8::HandleScope scope(env->GetIsolate()); | 2409   v8::Isolate* isolate = env->GetIsolate(); | 
| 2410   v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler(); | 2410   v8::HandleScope handle_scope(isolate); | 
| 2411   CompileRun("sin1 = Math.sin(1);"); | 2411   v8::HeapProfiler* heap_profiler = isolate->GetHeapProfiler(); | 
| 2412   LocalContext env2; | 2412 | 
| 2413   CompileRun("sin2 = Math.sin(2);"); | 2413   v8::Local<v8::ArrayBuffer> ab = v8::ArrayBuffer::New(isolate, 1024); | 
|  | 2414   CHECK_EQ(1024, static_cast<int>(ab->ByteLength())); | 
|  | 2415   CHECK(!ab->IsExternal()); | 
|  | 2416   v8::ArrayBuffer::Contents ab_contents = ab->Externalize(); | 
|  | 2417   CHECK(ab->IsExternal()); | 
|  | 2418 | 
|  | 2419   CHECK_EQ(1024, static_cast<int>(ab_contents.ByteLength())); | 
|  | 2420   void* data = ab_contents.Data(); | 
|  | 2421   ASSERT(data != NULL); | 
|  | 2422   v8::Local<v8::ArrayBuffer> ab2 = | 
|  | 2423       v8::ArrayBuffer::New(isolate, data, ab_contents.ByteLength()); | 
|  | 2424   CHECK(ab2->IsExternal()); | 
|  | 2425   env->Global()->Set(v8_str("ab1"), ab); | 
|  | 2426   env->Global()->Set(v8_str("ab2"), ab2); | 
|  | 2427 | 
|  | 2428   v8::Handle<v8::Value> result = CompileRun("ab2.byteLength"); | 
|  | 2429   CHECK_EQ(1024, result->Int32Value()); | 
|  | 2430 | 
| 2414   const v8::HeapSnapshot* snapshot = | 2431   const v8::HeapSnapshot* snapshot = | 
| 2415       heap_profiler->TakeHeapSnapshot(v8_str("snapshot")); | 2432       heap_profiler->TakeHeapSnapshot(v8_str("snapshot")); | 
| 2416   CHECK(ValidateSnapshot(snapshot)); | 2433   CHECK(ValidateSnapshot(snapshot)); | 
| 2417   // The 0th-child is (GC Roots), 1st is the user root. | 2434   const v8::HeapGraphNode* global = GetGlobalObject(snapshot); | 
| 2418   const v8::HeapGraphNode* global = | 2435   const v8::HeapGraphNode* ab1_node = | 
| 2419       snapshot->GetRoot()->GetChild(1)->GetToNode(); | 2436       GetProperty(global, v8::HeapGraphEdge::kProperty, "ab1"); | 
| 2420   const v8::HeapGraphNode* builtins = | 2437   CHECK_NE(NULL, ab1_node); | 
| 2421       GetProperty(global, v8::HeapGraphEdge::kInternal, "builtins"); | 2438   const v8::HeapGraphNode* ab1_data = | 
| 2422   CHECK_NE(NULL, builtins); | 2439       GetProperty(ab1_node, v8::HeapGraphEdge::kInternal, "backing_store"); | 
| 2423   const v8::HeapGraphNode* sin_table = | 2440   CHECK_NE(NULL, ab1_data); | 
| 2424       GetProperty(builtins, v8::HeapGraphEdge::kProperty, "kSinTable"); | 2441   const v8::HeapGraphNode* ab2_node = | 
| 2425   CHECK_NE(NULL, sin_table); | 2442       GetProperty(global, v8::HeapGraphEdge::kProperty, "ab2"); | 
| 2426   const v8::HeapGraphNode* buffer = | 2443   CHECK_NE(NULL, ab2_node); | 
| 2427       GetProperty(sin_table, v8::HeapGraphEdge::kInternal, "buffer"); | 2444   const v8::HeapGraphNode* ab2_data = | 
| 2428   CHECK_NE(NULL, buffer); | 2445       GetProperty(ab2_node, v8::HeapGraphEdge::kInternal, "backing_store"); | 
| 2429   const v8::HeapGraphNode* backing_store = | 2446   CHECK_NE(NULL, ab2_data); | 
| 2430       GetProperty(buffer, v8::HeapGraphEdge::kInternal, "backing_store"); | 2447   CHECK_EQ(ab1_data, ab2_data); | 
| 2431   CHECK_NE(NULL, backing_store); | 2448   CHECK_EQ(2, GetRetainersCount(snapshot, ab1_data)); | 
| 2432   int retainers = GetRetainersCount(snapshot, backing_store); | 2449   free(data); | 
| 2433   CHECK_EQ(2, retainers); |  | 
| 2434 } | 2450 } | 
| 2435 | 2451 | 
| 2436 | 2452 | 
| 2437 TEST(BoxObject) { | 2453 TEST(BoxObject) { | 
| 2438   v8::Isolate* isolate = CcTest::isolate(); | 2454   v8::Isolate* isolate = CcTest::isolate(); | 
| 2439   v8::HandleScope scope(isolate); | 2455   v8::HandleScope scope(isolate); | 
| 2440   LocalContext env; | 2456   LocalContext env; | 
| 2441   v8::Handle<v8::Object> global_proxy = env->Global(); | 2457   v8::Handle<v8::Object> global_proxy = env->Global(); | 
| 2442   v8::Handle<v8::Object> global = global_proxy->GetPrototype().As<v8::Object>(); | 2458   v8::Handle<v8::Object> global = global_proxy->GetPrototype().As<v8::Object>(); | 
| 2443 | 2459 | 
| (...skipping 10 matching lines...) Expand all  Loading... | 
| 2454   const v8::HeapGraphNode* global_node = GetGlobalObject(snapshot); | 2470   const v8::HeapGraphNode* global_node = GetGlobalObject(snapshot); | 
| 2455   const v8::HeapGraphNode* box_node = | 2471   const v8::HeapGraphNode* box_node = | 
| 2456       GetProperty(global_node, v8::HeapGraphEdge::kElement, "0"); | 2472       GetProperty(global_node, v8::HeapGraphEdge::kElement, "0"); | 
| 2457   CHECK_NE(NULL, box_node); | 2473   CHECK_NE(NULL, box_node); | 
| 2458   v8::String::Utf8Value box_node_name(box_node->GetName()); | 2474   v8::String::Utf8Value box_node_name(box_node->GetName()); | 
| 2459   CHECK_EQ("system / Box", *box_node_name); | 2475   CHECK_EQ("system / Box", *box_node_name); | 
| 2460   const v8::HeapGraphNode* box_value = | 2476   const v8::HeapGraphNode* box_value = | 
| 2461       GetProperty(box_node, v8::HeapGraphEdge::kInternal, "value"); | 2477       GetProperty(box_node, v8::HeapGraphEdge::kInternal, "value"); | 
| 2462   CHECK_NE(NULL, box_value); | 2478   CHECK_NE(NULL, box_value); | 
| 2463 } | 2479 } | 
| OLD | NEW | 
|---|