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

Side by Side Diff: src/handles.cc

Issue 15691017: Make assertion scopes thread safe. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 7 years, 6 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
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 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 439 matching lines...) Expand 10 before | Expand all | Expand 10 after
450 450
451 Handle<FixedArray> CalculateLineEnds(Handle<String> src, 451 Handle<FixedArray> CalculateLineEnds(Handle<String> src,
452 bool with_last_line) { 452 bool with_last_line) {
453 src = FlattenGetString(src); 453 src = FlattenGetString(src);
454 // Rough estimate of line count based on a roughly estimated average 454 // Rough estimate of line count based on a roughly estimated average
455 // length of (unpacked) code. 455 // length of (unpacked) code.
456 int line_count_estimate = src->length() >> 4; 456 int line_count_estimate = src->length() >> 4;
457 List<int> line_ends(line_count_estimate); 457 List<int> line_ends(line_count_estimate);
458 Isolate* isolate = src->GetIsolate(); 458 Isolate* isolate = src->GetIsolate();
459 { 459 {
460 AssertNoAllocation no_heap_allocation; // ensure vectors stay valid. 460 DisallowHeapAllocation no_allocation; // ensure vectors stay valid.
461 // Dispatch on type of strings. 461 // Dispatch on type of strings.
462 String::FlatContent content = src->GetFlatContent(); 462 String::FlatContent content = src->GetFlatContent();
463 ASSERT(content.IsFlat()); 463 ASSERT(content.IsFlat());
464 if (content.IsAscii()) { 464 if (content.IsAscii()) {
465 CalculateLineEnds(isolate, 465 CalculateLineEnds(isolate,
466 &line_ends, 466 &line_ends,
467 content.ToOneByteVector(), 467 content.ToOneByteVector(),
468 with_last_line); 468 with_last_line);
469 } else { 469 } else {
470 CalculateLineEnds(isolate, 470 CalculateLineEnds(isolate,
471 &line_ends, 471 &line_ends,
472 content.ToUC16Vector(), 472 content.ToUC16Vector(),
473 with_last_line); 473 with_last_line);
474 } 474 }
475 } 475 }
476 int line_count = line_ends.length(); 476 int line_count = line_ends.length();
477 Handle<FixedArray> array = isolate->factory()->NewFixedArray(line_count); 477 Handle<FixedArray> array = isolate->factory()->NewFixedArray(line_count);
478 for (int i = 0; i < line_count; i++) { 478 for (int i = 0; i < line_count; i++) {
479 array->set(i, Smi::FromInt(line_ends[i])); 479 array->set(i, Smi::FromInt(line_ends[i]));
480 } 480 }
481 return array; 481 return array;
482 } 482 }
483 483
484 484
485 // Convert code position into line number. 485 // Convert code position into line number.
486 int GetScriptLineNumber(Handle<Script> script, int code_pos) { 486 int GetScriptLineNumber(Handle<Script> script, int code_pos) {
487 InitScriptLineEnds(script); 487 InitScriptLineEnds(script);
488 AssertNoAllocation no_allocation; 488 DisallowHeapAllocation no_allocation;
489 FixedArray* line_ends_array = FixedArray::cast(script->line_ends()); 489 FixedArray* line_ends_array = FixedArray::cast(script->line_ends());
490 const int line_ends_len = line_ends_array->length(); 490 const int line_ends_len = line_ends_array->length();
491 491
492 if (!line_ends_len) return -1; 492 if (!line_ends_len) return -1;
493 493
494 if ((Smi::cast(line_ends_array->get(0)))->value() >= code_pos) { 494 if ((Smi::cast(line_ends_array->get(0)))->value() >= code_pos) {
495 return script->line_offset()->value(); 495 return script->line_offset()->value();
496 } 496 }
497 497
498 int left = 0; 498 int left = 0;
499 int right = line_ends_len; 499 int right = line_ends_len;
500 while (int half = (right - left) / 2) { 500 while (int half = (right - left) / 2) {
501 if ((Smi::cast(line_ends_array->get(left + half)))->value() > code_pos) { 501 if ((Smi::cast(line_ends_array->get(left + half)))->value() > code_pos) {
502 right -= half; 502 right -= half;
503 } else { 503 } else {
504 left += half; 504 left += half;
505 } 505 }
506 } 506 }
507 return right + script->line_offset()->value(); 507 return right + script->line_offset()->value();
508 } 508 }
509 509
510 // Convert code position into column number. 510 // Convert code position into column number.
511 int GetScriptColumnNumber(Handle<Script> script, int code_pos) { 511 int GetScriptColumnNumber(Handle<Script> script, int code_pos) {
512 int line_number = GetScriptLineNumber(script, code_pos); 512 int line_number = GetScriptLineNumber(script, code_pos);
513 if (line_number == -1) return -1; 513 if (line_number == -1) return -1;
514 514
515 AssertNoAllocation no_allocation; 515 DisallowHeapAllocation no_allocation;
516 FixedArray* line_ends_array = FixedArray::cast(script->line_ends()); 516 FixedArray* line_ends_array = FixedArray::cast(script->line_ends());
517 line_number = line_number - script->line_offset()->value(); 517 line_number = line_number - script->line_offset()->value();
518 if (line_number == 0) return code_pos + script->column_offset()->value(); 518 if (line_number == 0) return code_pos + script->column_offset()->value();
519 int prev_line_end_pos = 519 int prev_line_end_pos =
520 Smi::cast(line_ends_array->get(line_number - 1))->value(); 520 Smi::cast(line_ends_array->get(line_number - 1))->value();
521 return code_pos - (prev_line_end_pos + 1); 521 return code_pos - (prev_line_end_pos + 1);
522 } 522 }
523 523
524 int GetScriptLineNumberSafe(Handle<Script> script, int code_pos) { 524 int GetScriptLineNumberSafe(Handle<Script> script, int code_pos) {
525 AssertNoAllocation no_allocation; 525 DisallowHeapAllocation no_allocation;
526 if (!script->line_ends()->IsUndefined()) { 526 if (!script->line_ends()->IsUndefined()) {
527 return GetScriptLineNumber(script, code_pos); 527 return GetScriptLineNumber(script, code_pos);
528 } 528 }
529 // Slow mode: we do not have line_ends. We have to iterate through source. 529 // Slow mode: we do not have line_ends. We have to iterate through source.
530 if (!script->source()->IsString()) { 530 if (!script->source()->IsString()) {
531 return -1; 531 return -1;
532 } 532 }
533 String* source = String::cast(script->source()); 533 String* source = String::cast(script->source());
534 int line = 0; 534 int line = 0;
535 int len = source->length(); 535 int len = source->length();
(...skipping 387 matching lines...) Expand 10 before | Expand all | Expand 10 after
923 data->next = prev_next_; 923 data->next = prev_next_;
924 data->limit = prev_limit_; 924 data->limit = prev_limit_;
925 #ifdef DEBUG 925 #ifdef DEBUG
926 handles_detached_ = true; 926 handles_detached_ = true;
927 #endif 927 #endif
928 return deferred; 928 return deferred;
929 } 929 }
930 930
931 931
932 } } // namespace v8::internal 932 } } // namespace v8::internal
OLDNEW
« src/api.cc ('K') | « src/handles.h ('k') | src/handles-inl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698