Commit bf5c9af9 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}

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

Cr-Commit-Position: refs/heads/master@{#31805}
parent 152163c1
...@@ -1223,24 +1223,8 @@ void Genesis::InitializeGlobal(Handle<JSGlobalObject> global_object, ...@@ -1223,24 +1223,8 @@ 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);
{
// ES6 21.2.3.2.1
DataDescriptor field(factory->regexp_source_symbol(),
JSRegExp::kSourceFieldIndex, final,
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. // ECMA-262, section 15.10.7.5.
PropertyAttributes writable = PropertyAttributes writable =
static_cast<PropertyAttributes>(DONT_ENUM | DONT_DELETE); static_cast<PropertyAttributes>(DONT_ENUM | DONT_DELETE);
...@@ -1248,7 +1232,6 @@ void Genesis::InitializeGlobal(Handle<JSGlobalObject> global_object, ...@@ -1248,7 +1232,6 @@ void Genesis::InitializeGlobal(Handle<JSGlobalObject> global_object,
JSRegExp::kLastIndexFieldIndex, writable, JSRegExp::kLastIndexFieldIndex, writable,
Representation::Tagged()); Representation::Tagged());
initial_map->AppendDescriptor(&field); 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);
......
...@@ -6195,6 +6195,14 @@ class HObjectAccess final { ...@@ -6195,6 +6195,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);
......
...@@ -12644,6 +12644,26 @@ void HOptimizedGraphBuilder::GenerateRegExpExec(CallRuntime* call) { ...@@ -12644,6 +12644,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)));
......
...@@ -2235,6 +2235,8 @@ class HOptimizedGraphBuilder : public HGraphBuilder, public AstVisitor { ...@@ -2235,6 +2235,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(Likely) \ F(Likely) \
......
...@@ -185,12 +185,12 @@ define REGEXP_MULTILINE_MASK = 4; ...@@ -185,12 +185,12 @@ define REGEXP_MULTILINE_MASK = 4;
define REGEXP_STICKY_MASK = 8; define REGEXP_STICKY_MASK = 8;
define REGEXP_UNICODE_MASK = 16; define REGEXP_UNICODE_MASK = 16;
macro REGEXP_GLOBAL(regexp) = (regexp[regExpFlagsSymbol] & REGEXP_GLOBAL_MASK); macro REGEXP_GLOBAL(regexp) = (%_RegExpFlags(regexp) & REGEXP_GLOBAL_MASK);
macro REGEXP_IGNORE_CASE(regexp) = (regexp[regExpFlagsSymbol] & REGEXP_IGNORE_CASE_MASK); macro REGEXP_IGNORE_CASE(regexp) = (%_RegExpFlags(regexp) & REGEXP_IGNORE_CASE_MASK);
macro REGEXP_MULTILINE(regexp) = (regexp[regExpFlagsSymbol] & REGEXP_MULTILINE_MASK); macro REGEXP_MULTILINE(regexp) = (%_RegExpFlags(regexp) & REGEXP_MULTILINE_MASK);
macro REGEXP_STICKY(regexp) = (regexp[regExpFlagsSymbol] & REGEXP_STICKY_MASK); macro REGEXP_STICKY(regexp) = (%_RegExpFlags(regexp) & REGEXP_STICKY_MASK);
macro REGEXP_UNICODE(regexp) = (regexp[regExpFlagsSymbol] & REGEXP_UNICODE_MASK); macro REGEXP_UNICODE(regexp) = (%_RegExpFlags(regexp) & REGEXP_UNICODE_MASK);
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;
...@@ -334,14 +332,10 @@ function RegExpMakeCaptureGetter(n) { ...@@ -334,14 +332,10 @@ function RegExpMakeCaptureGetter(n) {
// ES6 21.2.5.4, 21.2.5.5, 21.2.5.7, 21.2.5.12, 21.2.5.15. // ES6 21.2.5.4, 21.2.5.5, 21.2.5.7, 21.2.5.12, 21.2.5.15.
function GetRegExpFlagGetter(name, mask) { function GetRegExpFlagGetter(name, mask) {
var getter = function() { var getter = function() {
if (!IS_SPEC_OBJECT(this)) { if (!IS_REGEXP(this)) {
throw MakeTypeError(kRegExpNonObject, name, TO_STRING(this)); throw MakeTypeError(kRegExpNonObject, name, TO_STRING(this));
} }
var flags = this[regExpFlagsSymbol]; return !!(%_RegExpFlags(this) & mask);
if (IS_UNDEFINED(flags)) {
throw MakeTypeError(kRegExpNonRegExp, TO_STRING(this));
}
return !!(flags & mask);
}; };
%FunctionSetName(getter, name); %FunctionSetName(getter, name);
%SetNativeFlag(getter); %SetNativeFlag(getter);
...@@ -351,15 +345,11 @@ function GetRegExpFlagGetter(name, mask) { ...@@ -351,15 +345,11 @@ function GetRegExpFlagGetter(name, mask) {
// ES6 21.2.5.10. // ES6 21.2.5.10.
function RegExpGetSource() { function RegExpGetSource() {
if (!IS_SPEC_OBJECT(this)) { if (!IS_REGEXP(this)) {
throw MakeTypeError(kRegExpNonObject, "RegExp.prototype.source", throw MakeTypeError(kRegExpNonObject, "RegExp.prototype.source",
TO_STRING(this)); TO_STRING(this));
} }
var source = this[regExpSourceSymbol]; return %_RegExpSource(this);
if (IS_UNDEFINED(source)) {
throw MakeTypeError(kRegExpNonRegExp, TO_STRING(this));
}
return source;
} }
%SetNativeFlag(RegExpGetSource); %SetNativeFlag(RegExpGetSource);
......
...@@ -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() {
......
...@@ -7699,6 +7699,8 @@ class JSRegExp: public JSObject { ...@@ -7699,6 +7699,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();
...@@ -7731,7 +7733,9 @@ class JSRegExp: public JSObject { ...@@ -7731,7 +7733,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;
...@@ -7780,10 +7784,8 @@ class JSRegExp: public JSObject { ...@@ -7780,10 +7784,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;
......
...@@ -559,6 +559,8 @@ namespace internal { ...@@ -559,6 +559,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