Commit 8f741738 authored by yangguo's avatar yangguo Committed by Commit bot

Use in-object fields instead of private symbols for regexp slots.

R=bmeurer@chromium.org

Committed: https://crrev.com/5a1e42c039ac3379ebe1e7e34fb8163e1ec1493e
Cr-Commit-Position: refs/heads/master@{#31791}

Committed: https://crrev.com/bf5c9af92ac0a5b7f020ac968d3d42ed06aa6144
Cr-Commit-Position: refs/heads/master@{#31805}

Review URL: https://codereview.chromium.org/1428203003

Cr-Commit-Position: refs/heads/master@{#31838}
parent 7f1fb29f
...@@ -1223,32 +1223,15 @@ void Genesis::InitializeGlobal(Handle<JSGlobalObject> global_object, ...@@ -1223,32 +1223,15 @@ void Genesis::InitializeGlobal(Handle<JSGlobalObject> global_object,
DCHECK_EQ(0, initial_map->GetInObjectProperties()); DCHECK_EQ(0, initial_map->GetInObjectProperties());
PropertyAttributes final = Map::EnsureDescriptorSlack(initial_map, 1);
static_cast<PropertyAttributes>(DONT_ENUM | DONT_DELETE | READ_ONLY);
Map::EnsureDescriptorSlack(initial_map, 5);
{ // ECMA-262, section 15.10.7.5.
// ES6 21.2.3.2.1 PropertyAttributes writable =
DataDescriptor field(factory->regexp_source_symbol(), static_cast<PropertyAttributes>(DONT_ENUM | DONT_DELETE);
JSRegExp::kSourceFieldIndex, final, DataDescriptor field(factory->last_index_string(),
Representation::Tagged()); JSRegExp::kLastIndexFieldIndex, writable,
initial_map->AppendDescriptor(&field); Representation::Tagged());
} initial_map->AppendDescriptor(&field);
{
DataDescriptor field(factory->regexp_flags_symbol(),
JSRegExp::kFlagsFieldIndex, final,
Representation::Smi());
initial_map->AppendDescriptor(&field);
}
{
// ECMA-262, section 15.10.7.5.
PropertyAttributes writable =
static_cast<PropertyAttributes>(DONT_ENUM | DONT_DELETE);
DataDescriptor field(factory->last_index_string(),
JSRegExp::kLastIndexFieldIndex, writable,
Representation::Tagged());
initial_map->AppendDescriptor(&field);
}
static const int num_fields = JSRegExp::kInObjectFieldCount; static const int num_fields = JSRegExp::kInObjectFieldCount;
initial_map->SetInObjectProperties(num_fields); initial_map->SetInObjectProperties(num_fields);
......
...@@ -6189,6 +6189,14 @@ class HObjectAccess final { ...@@ -6189,6 +6189,14 @@ class HObjectAccess final {
return HObjectAccess(kInobject, JSGlobalObject::kNativeContextOffset); return HObjectAccess(kInobject, JSGlobalObject::kNativeContextOffset);
} }
static HObjectAccess ForJSRegExpFlags() {
return HObjectAccess(kInobject, JSRegExp::kFlagsOffset);
}
static HObjectAccess ForJSRegExpSource() {
return HObjectAccess(kInobject, JSRegExp::kSourceOffset);
}
static HObjectAccess ForJSCollectionTable() { static HObjectAccess ForJSCollectionTable() {
return HObjectAccess::ForObservableJSObjectOffset( return HObjectAccess::ForObservableJSObjectOffset(
JSCollection::kTableOffset); JSCollection::kTableOffset);
......
...@@ -12625,6 +12625,26 @@ void HOptimizedGraphBuilder::GenerateRegExpExec(CallRuntime* call) { ...@@ -12625,6 +12625,26 @@ void HOptimizedGraphBuilder::GenerateRegExpExec(CallRuntime* call) {
} }
void HOptimizedGraphBuilder::GenerateRegExpFlags(CallRuntime* call) {
DCHECK_EQ(1, call->arguments()->length());
CHECK_ALIVE(VisitExpressions(call->arguments()));
HValue* regexp = Pop();
HInstruction* result =
New<HLoadNamedField>(regexp, nullptr, HObjectAccess::ForJSRegExpFlags());
return ast_context()->ReturnInstruction(result, call->id());
}
void HOptimizedGraphBuilder::GenerateRegExpSource(CallRuntime* call) {
DCHECK_EQ(1, call->arguments()->length());
CHECK_ALIVE(VisitExpressions(call->arguments()));
HValue* regexp = Pop();
HInstruction* result =
New<HLoadNamedField>(regexp, nullptr, HObjectAccess::ForJSRegExpSource());
return ast_context()->ReturnInstruction(result, call->id());
}
void HOptimizedGraphBuilder::GenerateDoubleLo(CallRuntime* call) { void HOptimizedGraphBuilder::GenerateDoubleLo(CallRuntime* call) {
DCHECK_EQ(1, call->arguments()->length()); DCHECK_EQ(1, call->arguments()->length());
CHECK_ALIVE(VisitForValue(call->arguments()->at(0))); CHECK_ALIVE(VisitForValue(call->arguments()->at(0)));
......
...@@ -2233,6 +2233,8 @@ class HOptimizedGraphBuilder : public HGraphBuilder, public AstVisitor { ...@@ -2233,6 +2233,8 @@ class HOptimizedGraphBuilder : public HGraphBuilder, public AstVisitor {
F(SubString) \ F(SubString) \
F(RegExpExec) \ F(RegExpExec) \
F(RegExpConstructResult) \ F(RegExpConstructResult) \
F(RegExpFlags) \
F(RegExpSource) \
F(NumberToString) \ F(NumberToString) \
F(DebugIsActive) \ F(DebugIsActive) \
F(HasInPrototypeChain) \ F(HasInPrototypeChain) \
......
...@@ -182,12 +182,12 @@ define REGEXP_NUMBER_OF_CAPTURES = 0; ...@@ -182,12 +182,12 @@ define REGEXP_NUMBER_OF_CAPTURES = 0;
define REGEXP_FIRST_CAPTURE = 3; define REGEXP_FIRST_CAPTURE = 3;
# Macros for internal slot access. # Macros for internal slot access.
macro REGEXP_GLOBAL(regexp) = (regexp[regExpFlagsSymbol] & 1); macro REGEXP_GLOBAL(regexp) = (%_RegExpFlags(regexp) & 1);
macro REGEXP_IGNORE_CASE(regexp) = (regexp[regExpFlagsSymbol] & 2); macro REGEXP_IGNORE_CASE(regexp) = (%_RegExpFlags(regexp) & 2);
macro REGEXP_MULTILINE(regexp) = (regexp[regExpFlagsSymbol] & 4); macro REGEXP_MULTILINE(regexp) = (%_RegExpFlags(regexp) & 4);
macro REGEXP_STICKY(regexp) = (regexp[regExpFlagsSymbol] & 8); macro REGEXP_STICKY(regexp) = (%_RegExpFlags(regexp) & 8);
macro REGEXP_UNICODE(regexp) = (regexp[regExpFlagsSymbol] & 16); macro REGEXP_UNICODE(regexp) = (%_RegExpFlags(regexp) & 16);
macro REGEXP_SOURCE(regexp) = (regexp[regExpSourceSymbol]); macro REGEXP_SOURCE(regexp) = (%_RegExpSource(regexp));
# We can't put macros in macros so we use constants here. # We can't put macros in macros so we use constants here.
# REGEXP_NUMBER_OF_CAPTURES # REGEXP_NUMBER_OF_CAPTURES
......
...@@ -14,8 +14,6 @@ var GlobalObject = global.Object; ...@@ -14,8 +14,6 @@ var GlobalObject = global.Object;
var GlobalRegExp = global.RegExp; var GlobalRegExp = global.RegExp;
var InternalPackedArray = utils.InternalPackedArray; var InternalPackedArray = utils.InternalPackedArray;
var MakeTypeError; var MakeTypeError;
var regExpFlagsSymbol = utils.ImportNow("regexp_flags_symbol");
var regExpSourceSymbol = utils.ImportNow("regexp_source_symbol");
utils.ImportFromExperimental(function(from) { utils.ImportFromExperimental(function(from) {
FLAG_harmony_tolength = from.FLAG_harmony_tolength; FLAG_harmony_tolength = from.FLAG_harmony_tolength;
......
...@@ -19,7 +19,6 @@ var MakeRangeError; ...@@ -19,7 +19,6 @@ var MakeRangeError;
var MakeTypeError; var MakeTypeError;
var RegExpExec; var RegExpExec;
var RegExpExecNoTests; var RegExpExecNoTests;
var regExpFlagsSymbol = utils.ImportNow("regexp_flags_symbol");
var RegExpLastMatchInfo; var RegExpLastMatchInfo;
utils.Import(function(from) { utils.Import(function(from) {
......
...@@ -6772,6 +6772,8 @@ ACCESSORS(JSTypedArray, raw_length, Object, kLengthOffset) ...@@ -6772,6 +6772,8 @@ ACCESSORS(JSTypedArray, raw_length, Object, kLengthOffset)
ACCESSORS(JSRegExp, data, Object, kDataOffset) ACCESSORS(JSRegExp, data, Object, kDataOffset)
ACCESSORS(JSRegExp, flags, Object, kFlagsOffset)
ACCESSORS(JSRegExp, source, Object, kSourceOffset)
JSRegExp::Type JSRegExp::TypeTag() { JSRegExp::Type JSRegExp::TypeTag() {
......
...@@ -7726,6 +7726,8 @@ class JSRegExp: public JSObject { ...@@ -7726,6 +7726,8 @@ class JSRegExp: public JSObject {
}; };
DECL_ACCESSORS(data, Object) DECL_ACCESSORS(data, Object)
DECL_ACCESSORS(flags, Object)
DECL_ACCESSORS(source, Object)
inline Type TypeTag(); inline Type TypeTag();
inline int CaptureCount(); inline int CaptureCount();
...@@ -7758,7 +7760,9 @@ class JSRegExp: public JSObject { ...@@ -7758,7 +7760,9 @@ class JSRegExp: public JSObject {
DECLARE_VERIFIER(JSRegExp) DECLARE_VERIFIER(JSRegExp)
static const int kDataOffset = JSObject::kHeaderSize; static const int kDataOffset = JSObject::kHeaderSize;
static const int kSize = kDataOffset + kPointerSize; static const int kSourceOffset = kDataOffset + kPointerSize;
static const int kFlagsOffset = kSourceOffset + kPointerSize;
static const int kSize = kFlagsOffset + kPointerSize;
// Indices in the data array. // Indices in the data array.
static const int kTagIndex = 0; static const int kTagIndex = 0;
...@@ -7807,10 +7811,8 @@ class JSRegExp: public JSObject { ...@@ -7807,10 +7811,8 @@ class JSRegExp: public JSObject {
FixedArray::kHeaderSize + kIrregexpCaptureCountIndex * kPointerSize; FixedArray::kHeaderSize + kIrregexpCaptureCountIndex * kPointerSize;
// In-object fields. // In-object fields.
static const int kSourceFieldIndex = 0; static const int kLastIndexFieldIndex = 0;
static const int kFlagsFieldIndex = 1; static const int kInObjectFieldCount = 1;
static const int kLastIndexFieldIndex = 2;
static const int kInObjectFieldCount = 3;
// The uninitialized value for a regexp code object. // The uninitialized value for a regexp code object.
static const int kUninitializedValue = -1; static const int kUninitializedValue = -1;
......
...@@ -788,6 +788,22 @@ RUNTIME_FUNCTION(Runtime_RegExpExec) { ...@@ -788,6 +788,22 @@ RUNTIME_FUNCTION(Runtime_RegExpExec) {
} }
RUNTIME_FUNCTION(Runtime_RegExpFlags) {
SealHandleScope shs(isolate);
DCHECK(args.length() == 1);
CONVERT_ARG_CHECKED(JSRegExp, regexp, 0);
return regexp->flags();
}
RUNTIME_FUNCTION(Runtime_RegExpSource) {
SealHandleScope shs(isolate);
DCHECK(args.length() == 1);
CONVERT_ARG_CHECKED(JSRegExp, regexp, 0);
return regexp->source();
}
RUNTIME_FUNCTION(Runtime_RegExpConstructResult) { RUNTIME_FUNCTION(Runtime_RegExpConstructResult) {
HandleScope handle_scope(isolate); HandleScope handle_scope(isolate);
DCHECK(args.length() == 3); DCHECK(args.length() == 3);
...@@ -924,37 +940,24 @@ RUNTIME_FUNCTION(Runtime_RegExpInitializeAndCompile) { ...@@ -924,37 +940,24 @@ RUNTIME_FUNCTION(Runtime_RegExpInitializeAndCompile) {
ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, escaped_source, ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, escaped_source,
EscapeRegExpSource(isolate, source)); EscapeRegExpSource(isolate, source));
regexp->set_source(*escaped_source);
regexp->set_flags(Smi::FromInt(flags.value()));
Map* map = regexp->map(); Map* map = regexp->map();
Object* constructor = map->GetConstructor(); Object* constructor = map->GetConstructor();
if (constructor->IsJSFunction() && if (constructor->IsJSFunction() &&
JSFunction::cast(constructor)->initial_map() == map) { JSFunction::cast(constructor)->initial_map() == map) {
// If we still have the original map, set in-object properties directly. // If we still have the original map, set in-object properties directly.
regexp->InObjectPropertyAtPut(JSRegExp::kSourceFieldIndex, *escaped_source);
regexp->InObjectPropertyAtPut(JSRegExp::kFlagsFieldIndex,
Smi::FromInt(flags.value()),
SKIP_WRITE_BARRIER);
regexp->InObjectPropertyAtPut(JSRegExp::kLastIndexFieldIndex, regexp->InObjectPropertyAtPut(JSRegExp::kLastIndexFieldIndex,
Smi::FromInt(0), SKIP_WRITE_BARRIER); Smi::FromInt(0), SKIP_WRITE_BARRIER);
} else { } else {
// Map has changed, so use generic, but slower, method. We also end here if // Map has changed, so use generic, but slower, method.
// the --harmony-regexp flag is set, because the initial map does not have
// space for the 'sticky' flag, since it is from the snapshot, but must work
// both with and without --harmony-regexp. When sticky comes out from under
// the flag, we will be able to use the fast initial map.
PropertyAttributes final =
static_cast<PropertyAttributes>(READ_ONLY | DONT_ENUM | DONT_DELETE);
PropertyAttributes writable = PropertyAttributes writable =
static_cast<PropertyAttributes>(DONT_ENUM | DONT_DELETE); static_cast<PropertyAttributes>(DONT_ENUM | DONT_DELETE);
Handle<Object> zero(Smi::FromInt(0), isolate);
JSObject::SetOwnPropertyIgnoreAttributes( JSObject::SetOwnPropertyIgnoreAttributes(
regexp, factory->regexp_source_symbol(), escaped_source, final) regexp, factory->last_index_string(),
Handle<Smi>(Smi::FromInt(0), isolate), writable)
.Check(); .Check();
JSObject::SetOwnPropertyIgnoreAttributes(
regexp, factory->regexp_flags_symbol(),
Handle<Smi>(Smi::FromInt(flags.value()), isolate), final)
.Check();
JSObject::SetOwnPropertyIgnoreAttributes(
regexp, factory->last_index_string(), zero, writable).Check();
} }
Handle<Object> result; Handle<Object> result;
......
...@@ -556,6 +556,8 @@ namespace internal { ...@@ -556,6 +556,8 @@ namespace internal {
F(StringReplaceGlobalRegExpWithString, 4, 1) \ F(StringReplaceGlobalRegExpWithString, 4, 1) \
F(StringSplit, 3, 1) \ F(StringSplit, 3, 1) \
F(RegExpExec, 4, 1) \ F(RegExpExec, 4, 1) \
F(RegExpFlags, 1, 1) \
F(RegExpSource, 1, 1) \
F(RegExpConstructResult, 3, 1) \ F(RegExpConstructResult, 3, 1) \
F(RegExpInitializeAndCompile, 3, 1) \ F(RegExpInitializeAndCompile, 3, 1) \
F(MaterializeRegExpLiteral, 4, 1) \ F(MaterializeRegExpLiteral, 4, 1) \
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment