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

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

Issue 990423004: Reland Just visit young array buffers during scavenge. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 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
« no previous file with comments | « src/serialize.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 the V8 project authors. All rights reserved. 1 // Copyright 2013 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 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
55 static bool HasArrayBufferInWeakList(Heap* heap, JSArrayBuffer* ab) { 55 static bool HasArrayBufferInWeakList(Heap* heap, JSArrayBuffer* ab) {
56 for (Object* o = heap->array_buffers_list(); 56 for (Object* o = heap->array_buffers_list();
57 !o->IsUndefined(); 57 !o->IsUndefined();
58 o = JSArrayBuffer::cast(o)->weak_next()) { 58 o = JSArrayBuffer::cast(o)->weak_next()) {
59 if (ab == o) return true; 59 if (ab == o) return true;
60 } 60 }
61 return false; 61 return false;
62 } 62 }
63 63
64 64
65 static int CountViews(JSArrayBuffer* array_buffer) { 65 static int CountViewsInNewSpaceList(Heap* heap, JSArrayBuffer* array_buffer) {
66 int count = 0;
67 for (Object* o = heap->new_array_buffer_views_list(); !o->IsUndefined();) {
68 JSArrayBufferView* view = JSArrayBufferView::cast(o);
69 if (array_buffer == view->buffer()) {
70 count++;
71 }
72 o = view->weak_next();
73 }
74 return count;
75 }
76
77
78 static int CountViews(Heap* heap, JSArrayBuffer* array_buffer) {
66 int count = 0; 79 int count = 0;
67 for (Object* o = array_buffer->weak_first_view(); 80 for (Object* o = array_buffer->weak_first_view();
68 !o->IsUndefined(); 81 !o->IsUndefined();
69 o = JSArrayBufferView::cast(o)->weak_next()) { 82 o = JSArrayBufferView::cast(o)->weak_next()) {
70 count++; 83 count++;
71 } 84 }
72 85
73 return count; 86 return count + CountViewsInNewSpaceList(heap, array_buffer);
74 } 87 }
75 88
76 static bool HasViewInWeakList(JSArrayBuffer* array_buffer, 89
77 JSArrayBufferView* ta) { 90 static bool HasViewInNewSpaceList(Heap* heap, JSArrayBufferView* ta) {
78 for (Object* o = array_buffer->weak_first_view(); 91 for (Object* o = heap->new_array_buffer_views_list(); !o->IsUndefined();
79 !o->IsUndefined();
80 o = JSArrayBufferView::cast(o)->weak_next()) { 92 o = JSArrayBufferView::cast(o)->weak_next()) {
81 if (ta == o) return true; 93 if (ta == o) return true;
82 } 94 }
83 return false; 95 return false;
84 } 96 }
85 97
86 98
99 static bool HasViewInWeakList(Heap* heap, JSArrayBuffer* array_buffer,
100 JSArrayBufferView* ta) {
101 for (Object* o = array_buffer->weak_first_view();
102 !o->IsUndefined();
103 o = JSArrayBufferView::cast(o)->weak_next()) {
104 if (ta == o) return true;
105 }
106 return HasViewInNewSpaceList(heap, ta);
107 }
108
109
87 TEST(WeakArrayBuffersFromApi) { 110 TEST(WeakArrayBuffersFromApi) {
88 v8::V8::Initialize(); 111 v8::V8::Initialize();
89 LocalContext context; 112 LocalContext context;
90 Isolate* isolate = GetIsolateFrom(&context); 113 Isolate* isolate = GetIsolateFrom(&context);
91 114
92 int start = CountArrayBuffersInWeakList(isolate->heap()); 115 int start = CountArrayBuffersInWeakList(isolate->heap());
93 { 116 {
94 v8::HandleScope s1(context->GetIsolate()); 117 v8::HandleScope s1(context->GetIsolate());
95 v8::Handle<v8::ArrayBuffer> ab1 = 118 v8::Handle<v8::ArrayBuffer> ab1 =
96 v8::ArrayBuffer::New(context->GetIsolate(), 256); 119 v8::ArrayBuffer::New(context->GetIsolate(), 256);
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
193 Handle<JSArrayBuffer> iab = v8::Utils::OpenHandle(*ab); 216 Handle<JSArrayBuffer> iab = v8::Utils::OpenHandle(*ab);
194 { 217 {
195 v8::HandleScope s2(context->GetIsolate()); 218 v8::HandleScope s2(context->GetIsolate());
196 v8::Handle<View> ta1 = View::New(ab, 0, 256); 219 v8::Handle<View> ta1 = View::New(ab, 0, 256);
197 { 220 {
198 v8::HandleScope s3(context->GetIsolate()); 221 v8::HandleScope s3(context->GetIsolate());
199 v8::Handle<View> ta2 = View::New(ab, 0, 128); 222 v8::Handle<View> ta2 = View::New(ab, 0, 128);
200 223
201 Handle<JSArrayBufferView> ita1 = v8::Utils::OpenHandle(*ta1); 224 Handle<JSArrayBufferView> ita1 = v8::Utils::OpenHandle(*ta1);
202 Handle<JSArrayBufferView> ita2 = v8::Utils::OpenHandle(*ta2); 225 Handle<JSArrayBufferView> ita2 = v8::Utils::OpenHandle(*ta2);
203 CHECK_EQ(2, CountViews(*iab)); 226 CHECK_EQ(2, CountViews(isolate->heap(), *iab));
204 CHECK(HasViewInWeakList(*iab, *ita1)); 227 CHECK(HasViewInWeakList(isolate->heap(), *iab, *ita1));
205 CHECK(HasViewInWeakList(*iab, *ita2)); 228 CHECK(HasViewInWeakList(isolate->heap(), *iab, *ita2));
206 } 229 }
207 isolate->heap()->CollectAllGarbage(Heap::kAbortIncrementalMarkingMask); 230 isolate->heap()->CollectAllGarbage(Heap::kAbortIncrementalMarkingMask);
208 CHECK_EQ(1, CountViews(*iab)); 231 CHECK_EQ(1, CountViews(isolate->heap(), *iab));
209 Handle<JSArrayBufferView> ita1 = v8::Utils::OpenHandle(*ta1); 232 Handle<JSArrayBufferView> ita1 = v8::Utils::OpenHandle(*ta1);
210 CHECK(HasViewInWeakList(*iab, *ita1)); 233 CHECK(HasViewInWeakList(isolate->heap(), *iab, *ita1));
211 } 234 }
212 isolate->heap()->CollectAllGarbage(Heap::kAbortIncrementalMarkingMask); 235 isolate->heap()->CollectAllGarbage(Heap::kAbortIncrementalMarkingMask);
213 236
214 CHECK_EQ(0, CountViews(*iab)); 237 CHECK_EQ(0, CountViews(isolate->heap(), *iab));
215 } 238 }
216 239
217 240
218 TEST(Uint8ArrayFromApi) { 241 TEST(Uint8ArrayFromApi) {
219 TestViewFromApi<v8::Uint8Array>(); 242 TestViewFromApi<v8::Uint8Array>();
220 } 243 }
221 244
222 245
223 TEST(Int8ArrayFromApi) { 246 TEST(Int8ArrayFromApi) {
224 TestViewFromApi<v8::Int8Array>(); 247 TestViewFromApi<v8::Int8Array>();
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
292 v8::Handle<v8::ArrayBuffer> ab = 315 v8::Handle<v8::ArrayBuffer> ab =
293 v8::Handle<v8::ArrayBuffer>::Cast(CompileRun("ab")); 316 v8::Handle<v8::ArrayBuffer>::Cast(CompileRun("ab"));
294 v8::Handle<TypedArray> ta1 = 317 v8::Handle<TypedArray> ta1 =
295 v8::Handle<TypedArray>::Cast(CompileRun("ta1")); 318 v8::Handle<TypedArray>::Cast(CompileRun("ta1"));
296 v8::Handle<TypedArray> ta2 = 319 v8::Handle<TypedArray> ta2 =
297 v8::Handle<TypedArray>::Cast(CompileRun("ta2")); 320 v8::Handle<TypedArray>::Cast(CompileRun("ta2"));
298 v8::Handle<TypedArray> ta3 = 321 v8::Handle<TypedArray> ta3 =
299 v8::Handle<TypedArray>::Cast(CompileRun("ta3")); 322 v8::Handle<TypedArray>::Cast(CompileRun("ta3"));
300 CHECK_EQ(1, CountArrayBuffersInWeakList(isolate->heap()) - start); 323 CHECK_EQ(1, CountArrayBuffersInWeakList(isolate->heap()) - start);
301 Handle<JSArrayBuffer> iab = v8::Utils::OpenHandle(*ab); 324 Handle<JSArrayBuffer> iab = v8::Utils::OpenHandle(*ab);
302 CHECK_EQ(3, CountViews(*iab)); 325 CHECK_EQ(3, CountViews(isolate->heap(), *iab));
303 CHECK(HasViewInWeakList(*iab, *v8::Utils::OpenHandle(*ta1))); 326 CHECK(HasViewInWeakList(isolate->heap(), *iab,
304 CHECK(HasViewInWeakList(*iab, *v8::Utils::OpenHandle(*ta2))); 327 *v8::Utils::OpenHandle(*ta1)));
305 CHECK(HasViewInWeakList(*iab, *v8::Utils::OpenHandle(*ta3))); 328 CHECK(HasViewInWeakList(isolate->heap(), *iab,
329 *v8::Utils::OpenHandle(*ta2)));
330 CHECK(HasViewInWeakList(isolate->heap(), *iab,
331 *v8::Utils::OpenHandle(*ta3)));
306 } 332 }
307 333
308 i::SNPrintF(source, "ta%d = null;", i); 334 i::SNPrintF(source, "ta%d = null;", i);
309 CompileRun(source.start()); 335 CompileRun(source.start());
310 isolate->heap()->CollectAllGarbage(Heap::kAbortIncrementalMarkingMask); 336 isolate->heap()->CollectAllGarbage(Heap::kAbortIncrementalMarkingMask);
311 337
312 CHECK_EQ(1, CountArrayBuffersInWeakList(isolate->heap()) - start); 338 CHECK_EQ(1, CountArrayBuffersInWeakList(isolate->heap()) - start);
313 339
314 { 340 {
315 v8::HandleScope s2(context->GetIsolate()); 341 v8::HandleScope s2(context->GetIsolate());
316 v8::Handle<v8::ArrayBuffer> ab = 342 v8::Handle<v8::ArrayBuffer> ab =
317 v8::Handle<v8::ArrayBuffer>::Cast(CompileRun("ab")); 343 v8::Handle<v8::ArrayBuffer>::Cast(CompileRun("ab"));
318 Handle<JSArrayBuffer> iab = v8::Utils::OpenHandle(*ab); 344 Handle<JSArrayBuffer> iab = v8::Utils::OpenHandle(*ab);
319 CHECK_EQ(2, CountViews(*iab)); 345 CHECK_EQ(2, CountViews(isolate->heap(), *iab));
320 for (int j = 1; j <= 3; j++) { 346 for (int j = 1; j <= 3; j++) {
321 if (j == i) continue; 347 if (j == i) continue;
322 i::SNPrintF(source, "ta%d", j); 348 i::SNPrintF(source, "ta%d", j);
323 v8::Handle<TypedArray> ta = 349 v8::Handle<TypedArray> ta =
324 v8::Handle<TypedArray>::Cast(CompileRun(source.start())); 350 v8::Handle<TypedArray>::Cast(CompileRun(source.start()));
325 CHECK(HasViewInWeakList(*iab, *v8::Utils::OpenHandle(*ta))); 351 CHECK(HasViewInWeakList(isolate->heap(), *iab,
352 *v8::Utils::OpenHandle(*ta)));
326 } 353 }
327 } 354 }
328 355
329 CompileRun("ta1 = null; ta2 = null; ta3 = null;"); 356 CompileRun("ta1 = null; ta2 = null; ta3 = null;");
330 isolate->heap()->CollectAllGarbage(Heap::kAbortIncrementalMarkingMask); 357 isolate->heap()->CollectAllGarbage(Heap::kAbortIncrementalMarkingMask);
331 358
332 CHECK_EQ(1, CountArrayBuffersInWeakList(isolate->heap()) - start); 359 CHECK_EQ(1, CountArrayBuffersInWeakList(isolate->heap()) - start);
333 360
334 { 361 {
335 v8::HandleScope s3(context->GetIsolate()); 362 v8::HandleScope s3(context->GetIsolate());
336 v8::Handle<v8::ArrayBuffer> ab = 363 v8::Handle<v8::ArrayBuffer> ab =
337 v8::Handle<v8::ArrayBuffer>::Cast(CompileRun("ab")); 364 v8::Handle<v8::ArrayBuffer>::Cast(CompileRun("ab"));
338 Handle<JSArrayBuffer> iab = v8::Utils::OpenHandle(*ab); 365 Handle<JSArrayBuffer> iab = v8::Utils::OpenHandle(*ab);
339 CHECK_EQ(0, CountViews(*iab)); 366 CHECK_EQ(0, CountViews(isolate->heap(), *iab));
340 } 367 }
341 } 368 }
342 } 369 }
343 370
344 371
345 TEST(Uint8ArrayFromScript) { 372 TEST(Uint8ArrayFromScript) {
346 TestTypedArrayFromScript<v8::Uint8Array>("Uint8Array"); 373 TestTypedArrayFromScript<v8::Uint8Array>("Uint8Array");
347 } 374 }
348 375
349 376
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
383 410
384 411
385 TEST(Uint8ClampedArrayFromScript) { 412 TEST(Uint8ClampedArrayFromScript) {
386 TestTypedArrayFromScript<v8::Uint8ClampedArray>("Uint8ClampedArray"); 413 TestTypedArrayFromScript<v8::Uint8ClampedArray>("Uint8ClampedArray");
387 } 414 }
388 415
389 416
390 TEST(DataViewFromScript) { 417 TEST(DataViewFromScript) {
391 TestTypedArrayFromScript<v8::DataView>("DataView"); 418 TestTypedArrayFromScript<v8::DataView>("DataView");
392 } 419 }
OLDNEW
« no previous file with comments | « src/serialize.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698