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

Side by Side Diff: src/ast/ast-value-factory.cc

Issue 2223523002: [Interpreter] Avoid dereferencing handles on BytecodeGenerator for AST operations. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@offheap_const_array
Patch Set: Created 4 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
OLDNEW
1 // Copyright 2014 the V8 project authors. All rights reserved. 1 // Copyright 2014 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 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 void AstRawString::Internalize(Isolate* isolate) { 86 void AstRawString::Internalize(Isolate* isolate) {
87 if (!string_.is_null()) return; 87 if (!string_.is_null()) return;
88 if (literal_bytes_.length() == 0) { 88 if (literal_bytes_.length() == 0) {
89 string_ = isolate->factory()->empty_string(); 89 string_ = isolate->factory()->empty_string();
90 } else { 90 } else {
91 AstRawStringInternalizationKey key(this); 91 AstRawStringInternalizationKey key(this);
92 string_ = StringTable::LookupKey(isolate, &key); 92 string_ = StringTable::LookupKey(isolate, &key);
93 } 93 }
94 } 94 }
95 95
96 96 bool AstRawString::AsArrayIndex(uint32_t* index,
97 bool AstRawString::AsArrayIndex(uint32_t* index) const { 97 HandleDereferenceMode deref_mode) const {
98 if (!string_.is_null()) 98 if (deref_mode == HandleDereferenceMode::kHandleDereferenceAllowed &&
99 !string_.is_null())
99 return string_->AsArrayIndex(index); 100 return string_->AsArrayIndex(index);
100 if (!is_one_byte_ || literal_bytes_.length() == 0 || 101 if (!is_one_byte_ || literal_bytes_.length() == 0 ||
101 literal_bytes_.length() > String::kMaxArrayIndexSize) 102 literal_bytes_.length() > String::kMaxArrayIndexSize)
102 return false; 103 return false;
103 OneByteStringStream stream(literal_bytes_); 104 OneByteStringStream stream(literal_bytes_);
104 return StringToArrayIndex(&stream, index); 105 return StringToArrayIndex(&stream, index);
105 } 106 }
106 107
107 108
108 bool AstRawString::IsOneByteEqualTo(const char* data) const { 109 bool AstRawString::IsOneByteEqualTo(const char* data) const {
109 int length = static_cast<int>(strlen(data)); 110 int length = static_cast<int>(strlen(data));
110 if (is_one_byte_ && literal_bytes_.length() == length) { 111 if (is_one_byte_ && literal_bytes_.length() == length) {
111 const char* token = reinterpret_cast<const char*>(literal_bytes_.start()); 112 const char* token = reinterpret_cast<const char*>(literal_bytes_.start());
112 return !strncmp(token, data, length); 113 return !strncmp(token, data, length);
113 } 114 }
114 return false; 115 return false;
115 } 116 }
116 117
117 118
118 void AstConsString::Internalize(Isolate* isolate) { 119 void AstConsString::Internalize(Isolate* isolate) {
119 // AstRawStrings are internalized before AstConsStrings so left and right are 120 // AstRawStrings are internalized before AstConsStrings so left and right are
120 // already internalized. 121 // already internalized.
121 string_ = isolate->factory() 122 string_ = isolate->factory()
122 ->NewConsString(left_->string(), right_->string()) 123 ->NewConsString(left_->string(), right_->string())
123 .ToHandleChecked(); 124 .ToHandleChecked();
124 } 125 }
125 126
126 127 bool AstValue::IsPropertyName(HandleDereferenceMode deref_mode) const {
127 bool AstValue::IsPropertyName() const {
128 if (type_ == STRING) { 128 if (type_ == STRING) {
129 uint32_t index; 129 uint32_t index;
130 return !string_->AsArrayIndex(&index); 130 return !string_->AsArrayIndex(&index, deref_mode);
131 } 131 }
132 return false; 132 return false;
133 } 133 }
134 134
135 135
136 bool AstValue::BooleanValue() const { 136 bool AstValue::BooleanValue() const {
137 switch (type_) { 137 switch (type_) {
138 case STRING: 138 case STRING:
139 DCHECK(string_ != NULL); 139 DCHECK(string_ != NULL);
140 return !string_->IsEmpty(); 140 return !string_->IsEmpty();
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
256 } 256 }
257 return new_string; 257 return new_string;
258 } 258 }
259 259
260 260
261 void AstValueFactory::Internalize(Isolate* isolate) { 261 void AstValueFactory::Internalize(Isolate* isolate) {
262 if (isolate_) { 262 if (isolate_) {
263 // Everything is already internalized. 263 // Everything is already internalized.
264 return; 264 return;
265 } 265 }
266
267 // Create a canonical handle scope if compiling ignition bytecode. This is
268 // required by the constant array builder to de-duplicate common objects
269 // without dereferencing handles.
270 std::unique_ptr<CanonicalHandleScope> canonical;
271 if (FLAG_ignition) canonical.reset(new CanonicalHandleScope(isolate));
272
marja 2016/08/08 08:20:13 This code snippet seems to be on a wrong abstracti
rmcilroy 2016/08/08 13:05:56 Moved up to api.cc and compiler-dispatcher-job.cc.
266 // Strings need to be internalized before values, because values refer to 273 // Strings need to be internalized before values, because values refer to
267 // strings. 274 // strings.
268 for (int i = 0; i < strings_.length(); ++i) { 275 for (int i = 0; i < strings_.length(); ++i) {
269 strings_[i]->Internalize(isolate); 276 strings_[i]->Internalize(isolate);
270 } 277 }
271 for (int i = 0; i < values_.length(); ++i) { 278 for (int i = 0; i < values_.length(); ++i) {
272 values_[i]->Internalize(isolate); 279 values_[i]->Internalize(isolate);
273 } 280 }
274 isolate_ = isolate; 281 isolate_ = isolate;
275 } 282 }
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
406 length) == 0; 413 length) == 0;
407 } else { 414 } else {
408 return CompareCharsUnsigned(reinterpret_cast<const uint16_t*>(l), 415 return CompareCharsUnsigned(reinterpret_cast<const uint16_t*>(l),
409 reinterpret_cast<const uint16_t*>(r), 416 reinterpret_cast<const uint16_t*>(r),
410 length) == 0; 417 length) == 0;
411 } 418 }
412 } 419 }
413 } 420 }
414 } // namespace internal 421 } // namespace internal
415 } // namespace v8 422 } // namespace v8
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698