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,24 +1223,8 @@ void Genesis::InitializeGlobal(Handle<JSGlobalObject> global_object,
DCHECK_EQ(0, initial_map->GetInObjectProperties());
PropertyAttributes final =
static_cast<PropertyAttributes>(DONT_ENUM | DONT_DELETE | READ_ONLY);
Map::EnsureDescriptorSlack(initial_map, 5);
Map::EnsureDescriptorSlack(initial_map, 1);
{
// 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.
PropertyAttributes writable =
static_cast<PropertyAttributes>(DONT_ENUM | DONT_DELETE);
......@@ -1248,7 +1232,6 @@ void Genesis::InitializeGlobal(Handle<JSGlobalObject> global_object,
JSRegExp::kLastIndexFieldIndex, writable,
Representation::Tagged());
initial_map->AppendDescriptor(&field);
}
static const int num_fields = JSRegExp::kInObjectFieldCount;
initial_map->SetInObjectProperties(num_fields);
......
......@@ -6189,6 +6189,14 @@ class HObjectAccess final {
return HObjectAccess(kInobject, JSGlobalObject::kNativeContextOffset);
}
static HObjectAccess ForJSRegExpFlags() {
return HObjectAccess(kInobject, JSRegExp::kFlagsOffset);
}
static HObjectAccess ForJSRegExpSource() {
return HObjectAccess(kInobject, JSRegExp::kSourceOffset);
}
static HObjectAccess ForJSCollectionTable() {
return HObjectAccess::ForObservableJSObjectOffset(
JSCollection::kTableOffset);
......
......@@ -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) {
DCHECK_EQ(1, call->arguments()->length());
CHECK_ALIVE(VisitForValue(call->arguments()->at(0)));
......
......@@ -2233,6 +2233,8 @@ class HOptimizedGraphBuilder : public HGraphBuilder, public AstVisitor {
F(SubString) \
F(RegExpExec) \
F(RegExpConstructResult) \
F(RegExpFlags) \
F(RegExpSource) \
F(NumberToString) \
F(DebugIsActive) \
F(HasInPrototypeChain) \
......
......@@ -182,12 +182,12 @@ define REGEXP_NUMBER_OF_CAPTURES = 0;
define REGEXP_FIRST_CAPTURE = 3;
# Macros for internal slot access.
macro REGEXP_GLOBAL(regexp) = (regexp[regExpFlagsSymbol] & 1);
macro REGEXP_IGNORE_CASE(regexp) = (regexp[regExpFlagsSymbol] & 2);
macro REGEXP_MULTILINE(regexp) = (regexp[regExpFlagsSymbol] & 4);
macro REGEXP_STICKY(regexp) = (regexp[regExpFlagsSymbol] & 8);
macro REGEXP_UNICODE(regexp) = (regexp[regExpFlagsSymbol] & 16);
macro REGEXP_SOURCE(regexp) = (regexp[regExpSourceSymbol]);
macro REGEXP_GLOBAL(regexp) = (%_RegExpFlags(regexp) & 1);
macro REGEXP_IGNORE_CASE(regexp) = (%_RegExpFlags(regexp) & 2);
macro REGEXP_MULTILINE(regexp) = (%_RegExpFlags(regexp) & 4);
macro REGEXP_STICKY(regexp) = (%_RegExpFlags(regexp) & 8);
macro REGEXP_UNICODE(regexp) = (%_RegExpFlags(regexp) & 16);
macro REGEXP_SOURCE(regexp) = (%_RegExpSource(regexp));
# We can't put macros in macros so we use constants here.
# REGEXP_NUMBER_OF_CAPTURES
......
......@@ -14,8 +14,6 @@ var GlobalObject = global.Object;
var GlobalRegExp = global.RegExp;
var InternalPackedArray = utils.InternalPackedArray;
var MakeTypeError;
var regExpFlagsSymbol = utils.ImportNow("regexp_flags_symbol");
var regExpSourceSymbol = utils.ImportNow("regexp_source_symbol");
utils.ImportFromExperimental(function(from) {
FLAG_harmony_tolength = from.FLAG_harmony_tolength;
......
......@@ -19,7 +19,6 @@ var MakeRangeError;
var MakeTypeError;
var RegExpExec;
var RegExpExecNoTests;
var regExpFlagsSymbol = utils.ImportNow("regexp_flags_symbol");
var RegExpLastMatchInfo;
utils.Import(function(from) {
......
......@@ -6772,6 +6772,8 @@ ACCESSORS(JSTypedArray, raw_length, Object, kLengthOffset)
ACCESSORS(JSRegExp, data, Object, kDataOffset)
ACCESSORS(JSRegExp, flags, Object, kFlagsOffset)
ACCESSORS(JSRegExp, source, Object, kSourceOffset)
JSRegExp::Type JSRegExp::TypeTag() {
......
......@@ -7726,6 +7726,8 @@ class JSRegExp: public JSObject {
};
DECL_ACCESSORS(data, Object)
DECL_ACCESSORS(flags, Object)
DECL_ACCESSORS(source, Object)
inline Type TypeTag();
inline int CaptureCount();
......@@ -7758,7 +7760,9 @@ class JSRegExp: public JSObject {
DECLARE_VERIFIER(JSRegExp)
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.
static const int kTagIndex = 0;
......@@ -7807,10 +7811,8 @@ class JSRegExp: public JSObject {
FixedArray::kHeaderSize + kIrregexpCaptureCountIndex * kPointerSize;
// In-object fields.
static const int kSourceFieldIndex = 0;
static const int kFlagsFieldIndex = 1;
static const int kLastIndexFieldIndex = 2;
static const int kInObjectFieldCount = 3;
static const int kLastIndexFieldIndex = 0;
static const int kInObjectFieldCount = 1;
// The uninitialized value for a regexp code object.
static const int kUninitializedValue = -1;
......
......@@ -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) {
HandleScope handle_scope(isolate);
DCHECK(args.length() == 3);
......@@ -924,37 +940,24 @@ RUNTIME_FUNCTION(Runtime_RegExpInitializeAndCompile) {
ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, escaped_source,
EscapeRegExpSource(isolate, source));
regexp->set_source(*escaped_source);
regexp->set_flags(Smi::FromInt(flags.value()));
Map* map = regexp->map();
Object* constructor = map->GetConstructor();
if (constructor->IsJSFunction() &&
JSFunction::cast(constructor)->initial_map() == map) {
// 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,
Smi::FromInt(0), SKIP_WRITE_BARRIER);
} else {
// Map has changed, so use generic, but slower, method. We also end here if
// 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);
// Map has changed, so use generic, but slower, method.
PropertyAttributes writable =
static_cast<PropertyAttributes>(DONT_ENUM | DONT_DELETE);
Handle<Object> zero(Smi::FromInt(0), isolate);
JSObject::SetOwnPropertyIgnoreAttributes(
regexp, factory->regexp_source_symbol(), escaped_source, final)
regexp, factory->last_index_string(),
Handle<Smi>(Smi::FromInt(0), isolate), writable)
.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;
......
......@@ -556,6 +556,8 @@ namespace internal {
F(StringReplaceGlobalRegExpWithString, 4, 1) \
F(StringSplit, 3, 1) \
F(RegExpExec, 4, 1) \
F(RegExpFlags, 1, 1) \
F(RegExpSource, 1, 1) \
F(RegExpConstructResult, 3, 1) \
F(RegExpInitializeAndCompile, 3, 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