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

Side by Side Diff: src/api.cc

Issue 462643002: Small clean up of externalizing strings. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: change Created 6 years, 4 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 | « no previous file | src/factory.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 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "src/api.h" 5 #include "src/api.h"
6 6
7 #include <string.h> // For memcpy, strlen. 7 #include <string.h> // For memcpy, strlen.
8 #ifdef V8_USE_ADDRESS_SANITIZER 8 #ifdef V8_USE_ADDRESS_SANITIZER
9 #include <sanitizer/asan_interface.h> 9 #include <sanitizer/asan_interface.h>
10 #endif // V8_USE_ADDRESS_SANITIZER 10 #endif // V8_USE_ADDRESS_SANITIZER
(...skipping 5457 matching lines...) Expand 10 before | Expand all | Expand 10 after
5468 CHECK(resource && resource->data()); 5468 CHECK(resource && resource->data());
5469 i::Handle<i::String> result = NewExternalStringHandle(i_isolate, resource); 5469 i::Handle<i::String> result = NewExternalStringHandle(i_isolate, resource);
5470 i_isolate->heap()->external_string_table()->AddString(*result); 5470 i_isolate->heap()->external_string_table()->AddString(*result);
5471 return Utils::ToLocal(result); 5471 return Utils::ToLocal(result);
5472 } 5472 }
5473 5473
5474 5474
5475 bool v8::String::MakeExternal(v8::String::ExternalStringResource* resource) { 5475 bool v8::String::MakeExternal(v8::String::ExternalStringResource* resource) {
5476 i::Handle<i::String> obj = Utils::OpenHandle(this); 5476 i::Handle<i::String> obj = Utils::OpenHandle(this);
5477 i::Isolate* isolate = obj->GetIsolate(); 5477 i::Isolate* isolate = obj->GetIsolate();
5478 if (i::StringShape(*obj).IsExternalTwoByte()) { 5478 if (i::StringShape(*obj).IsExternal()) {
5479 return false; // Already an external string. 5479 return false; // Already an external string.
5480 } 5480 }
5481 ENTER_V8(isolate); 5481 ENTER_V8(isolate);
5482 if (isolate->string_tracker()->IsFreshUnusedString(obj)) { 5482 if (isolate->string_tracker()->IsFreshUnusedString(obj)) {
5483 return false; 5483 return false;
5484 } 5484 }
5485 if (isolate->heap()->IsInGCPostProcessing()) { 5485 if (isolate->heap()->IsInGCPostProcessing()) {
5486 return false; 5486 return false;
5487 } 5487 }
5488 CHECK(resource && resource->data()); 5488 CHECK(resource && resource->data());
5489 5489
5490 bool result = obj->MakeExternal(resource); 5490 bool result = obj->MakeExternal(resource);
5491 // Assert that if CanMakeExternal(), then externalizing actually succeeds.
5492 DCHECK(!CanMakeExternal() || result);
5491 if (result) { 5493 if (result) {
5492 DCHECK(obj->IsExternalString()); 5494 DCHECK(obj->IsExternalString());
5493 isolate->heap()->external_string_table()->AddString(*obj); 5495 isolate->heap()->external_string_table()->AddString(*obj);
5494 } 5496 }
5495 return result; 5497 return result;
5496 } 5498 }
5497 5499
5498 5500
5499 Local<String> v8::String::NewExternal( 5501 Local<String> v8::String::NewExternal(
5500 Isolate* isolate, 5502 Isolate* isolate,
5501 v8::String::ExternalAsciiStringResource* resource) { 5503 v8::String::ExternalAsciiStringResource* resource) {
5502 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); 5504 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
5503 EnsureInitializedForIsolate(i_isolate, "v8::String::NewExternal()"); 5505 EnsureInitializedForIsolate(i_isolate, "v8::String::NewExternal()");
5504 LOG_API(i_isolate, "String::NewExternal"); 5506 LOG_API(i_isolate, "String::NewExternal");
5505 ENTER_V8(i_isolate); 5507 ENTER_V8(i_isolate);
5506 CHECK(resource && resource->data()); 5508 CHECK(resource && resource->data());
5507 i::Handle<i::String> result = 5509 i::Handle<i::String> result =
5508 NewExternalAsciiStringHandle(i_isolate, resource); 5510 NewExternalAsciiStringHandle(i_isolate, resource);
5509 i_isolate->heap()->external_string_table()->AddString(*result); 5511 i_isolate->heap()->external_string_table()->AddString(*result);
5510 return Utils::ToLocal(result); 5512 return Utils::ToLocal(result);
5511 } 5513 }
5512 5514
5513 5515
5514 bool v8::String::MakeExternal( 5516 bool v8::String::MakeExternal(
5515 v8::String::ExternalAsciiStringResource* resource) { 5517 v8::String::ExternalAsciiStringResource* resource) {
5516 i::Handle<i::String> obj = Utils::OpenHandle(this); 5518 i::Handle<i::String> obj = Utils::OpenHandle(this);
5517 i::Isolate* isolate = obj->GetIsolate(); 5519 i::Isolate* isolate = obj->GetIsolate();
5518 if (i::StringShape(*obj).IsExternalTwoByte()) { 5520 if (i::StringShape(*obj).IsExternal()) {
5519 return false; // Already an external string. 5521 return false; // Already an external string.
5520 } 5522 }
5521 ENTER_V8(isolate); 5523 ENTER_V8(isolate);
5522 if (isolate->string_tracker()->IsFreshUnusedString(obj)) { 5524 if (isolate->string_tracker()->IsFreshUnusedString(obj)) {
5523 return false; 5525 return false;
5524 } 5526 }
5525 if (isolate->heap()->IsInGCPostProcessing()) { 5527 if (isolate->heap()->IsInGCPostProcessing()) {
5526 return false; 5528 return false;
5527 } 5529 }
5528 CHECK(resource && resource->data()); 5530 CHECK(resource && resource->data());
5529 5531
5530 bool result = obj->MakeExternal(resource); 5532 bool result = obj->MakeExternal(resource);
5533 // Assert that if CanMakeExternal(), then externalizing actually succeeds.
5534 DCHECK(!CanMakeExternal() || result);
5531 if (result) { 5535 if (result) {
5532 DCHECK(obj->IsExternalString()); 5536 DCHECK(obj->IsExternalString());
5533 isolate->heap()->external_string_table()->AddString(*obj); 5537 isolate->heap()->external_string_table()->AddString(*obj);
5534 } 5538 }
5535 return result; 5539 return result;
5536 } 5540 }
5537 5541
5538 5542
5539 bool v8::String::CanMakeExternal() { 5543 bool v8::String::CanMakeExternal() {
5540 if (!internal::FLAG_clever_optimizations) return false; 5544 if (!internal::FLAG_clever_optimizations) return false;
(...skipping 2093 matching lines...) Expand 10 before | Expand all | Expand 10 after
7634 Isolate* isolate = reinterpret_cast<Isolate*>(info.GetIsolate()); 7638 Isolate* isolate = reinterpret_cast<Isolate*>(info.GetIsolate());
7635 Address callback_address = 7639 Address callback_address =
7636 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); 7640 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback));
7637 VMState<EXTERNAL> state(isolate); 7641 VMState<EXTERNAL> state(isolate);
7638 ExternalCallbackScope call_scope(isolate, callback_address); 7642 ExternalCallbackScope call_scope(isolate, callback_address);
7639 callback(info); 7643 callback(info);
7640 } 7644 }
7641 7645
7642 7646
7643 } } // namespace v8::internal 7647 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « no previous file | src/factory.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698