Skip to content

Commit

Permalink
Introduce LiteralsArray to hide it's implementation.
Browse files Browse the repository at this point in the history
The LiteralsArray will soon hold a type feedback vector. Code treats it as an
ordinary fixed array, and needs to stop that.

BUG=

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

Cr-Commit-Position: refs/heads/master@{#31000}
  • Loading branch information
ripsawridge authored and Commit bot committed Sep 29, 2015
1 parent 02af9b8 commit d8cdd69
Show file tree
Hide file tree
Showing 25 changed files with 185 additions and 72 deletions.
2 changes: 1 addition & 1 deletion src/arm/lithium-codegen-arm.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5398,7 +5398,7 @@ void LCodeGen::DoRegExpLiteral(LRegExpLiteral* instr) {
// r0 = regexp literal clone.
// r2-5 are used as temporaries.
int literal_offset =
FixedArray::OffsetOfElementAt(instr->hydrogen()->literal_index());
LiteralsArray::OffsetOfLiteralAt(instr->hydrogen()->literal_index());
__ Move(r6, instr->hydrogen()->literals());
__ ldr(r1, FieldMemOperand(r6, literal_offset));
__ LoadRoot(ip, Heap::kUndefinedValueRootIndex);
Expand Down
2 changes: 1 addition & 1 deletion src/arm64/lithium-codegen-arm64.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5648,7 +5648,7 @@ void LCodeGen::DoRegExpLiteral(LRegExpLiteral* instr) {
// x0 = regexp literal clone.
// x10-x12 are used as temporaries.
int literal_offset =
FixedArray::OffsetOfElementAt(instr->hydrogen()->literal_index());
LiteralsArray::OffsetOfLiteralAt(instr->hydrogen()->literal_index());
__ LoadObject(x7, instr->hydrogen()->literals());
__ Ldr(x1, FieldMemOperand(x7, literal_offset));
__ JumpIfNotRoot(x1, Heap::kUndefinedValueRootIndex, &materialized);
Expand Down
10 changes: 6 additions & 4 deletions src/code-stubs-hydrogen.cc
Original file line number Diff line number Diff line change
Expand Up @@ -442,8 +442,9 @@ HValue* CodeStubGraphBuilder<FastCloneShallowArrayStub>::BuildCodeStub() {
// so that it doesn't build and eager frame.
info()->MarkMustNotHaveEagerFrame();

HInstruction* allocation_site =
Add<HLoadKeyed>(GetParameter(0), GetParameter(1), nullptr, FAST_ELEMENTS);
HInstruction* allocation_site = Add<HLoadKeyed>(
GetParameter(0), GetParameter(1), nullptr, FAST_ELEMENTS,
NEVER_RETURN_HOLE, LiteralsArray::kOffsetToFirstLiteral - kHeapObjectTag);
IfBuilder checker(this);
checker.IfNot<HCompareObjectEqAndBranch, HValue*>(allocation_site,
undefined);
Expand Down Expand Up @@ -504,8 +505,9 @@ template <>
HValue* CodeStubGraphBuilder<FastCloneShallowObjectStub>::BuildCodeStub() {
HValue* undefined = graph()->GetConstantUndefined();

HInstruction* allocation_site =
Add<HLoadKeyed>(GetParameter(0), GetParameter(1), nullptr, FAST_ELEMENTS);
HInstruction* allocation_site = Add<HLoadKeyed>(
GetParameter(0), GetParameter(1), nullptr, FAST_ELEMENTS,
NEVER_RETURN_HOLE, LiteralsArray::kOffsetToFirstLiteral - kHeapObjectTag);

IfBuilder checker(this);
checker.IfNot<HCompareObjectEqAndBranch, HValue*>(allocation_site,
Expand Down
2 changes: 1 addition & 1 deletion src/compiler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -788,7 +788,7 @@ static void InsertCodeIntoOptimizedCodeMap(CompilationInfo* info) {
// Cache optimized context-specific code.
if (FLAG_cache_optimized_code) {
Handle<SharedFunctionInfo> shared(function->shared());
Handle<FixedArray> literals(function->literals());
Handle<LiteralsArray> literals(function->literals());
Handle<Context> native_context(function->context()->native_context());
SharedFunctionInfo::AddToOptimizedCodeMap(shared, native_context, code,
literals, info->osr_ast_id());
Expand Down
6 changes: 4 additions & 2 deletions src/debug/liveedit.cc
Original file line number Diff line number Diff line change
Expand Up @@ -995,10 +995,12 @@ class LiteralFixer {
// collect all functions and fix their literal arrays.
Handle<FixedArray> function_instances =
CollectJSFunctions(shared_info, isolate);
Handle<TypeFeedbackVector> vector(shared_info->feedback_vector());

for (int i = 0; i < function_instances->length(); i++) {
Handle<JSFunction> fun(JSFunction::cast(function_instances->get(i)));
Handle<FixedArray> new_literals =
isolate->factory()->NewFixedArray(new_literal_count);
Handle<LiteralsArray> new_literals =
LiteralsArray::New(isolate, vector, new_literal_count, TENURED);
fun->set_literals(*new_literals);
}

Expand Down
4 changes: 3 additions & 1 deletion src/factory.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1342,7 +1342,9 @@ Handle<JSFunction> Factory::NewFunctionFromSharedFunctionInfo(

} else if (!info->bound()) {
int number_of_literals = info->num_literals();
Handle<FixedArray> literals = NewFixedArray(number_of_literals, pretenure);
Handle<LiteralsArray> literals =
LiteralsArray::New(isolate(), handle(info->feedback_vector()),
number_of_literals, pretenure);
result->set_literals(*literals);
// Cache context-specific literals.
if (FLAG_cache_optimized_code) {
Expand Down
3 changes: 1 addition & 2 deletions src/full-codegen/arm/full-codegen-arm.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1498,8 +1498,7 @@ void FullCodeGenerator::VisitRegExpLiteral(RegExpLiteral* expr) {
// r0 = RegExp literal clone
__ ldr(r0, MemOperand(fp, JavaScriptFrameConstants::kFunctionOffset));
__ ldr(r4, FieldMemOperand(r0, JSFunction::kLiteralsOffset));
int literal_offset =
FixedArray::kHeaderSize + expr->literal_index() * kPointerSize;
int literal_offset = LiteralsArray::OffsetOfLiteralAt(expr->literal_index());
__ ldr(r5, FieldMemOperand(r4, literal_offset));
__ LoadRoot(ip, Heap::kUndefinedValueRootIndex);
__ cmp(r5, ip);
Expand Down
3 changes: 1 addition & 2 deletions src/full-codegen/arm64/full-codegen-arm64.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1487,8 +1487,7 @@ void FullCodeGenerator::VisitRegExpLiteral(RegExpLiteral* expr) {
// x0 = RegExp literal clone
__ Ldr(x10, MemOperand(fp, JavaScriptFrameConstants::kFunctionOffset));
__ Ldr(x4, FieldMemOperand(x10, JSFunction::kLiteralsOffset));
int literal_offset =
FixedArray::kHeaderSize + expr->literal_index() * kPointerSize;
int literal_offset = LiteralsArray::OffsetOfLiteralAt(expr->literal_index());
__ Ldr(x5, FieldMemOperand(x4, literal_offset));
__ JumpIfNotRoot(x5, Heap::kUndefinedValueRootIndex, &materialized);

Expand Down
3 changes: 1 addition & 2 deletions src/full-codegen/ia32/full-codegen-ia32.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1422,8 +1422,7 @@ void FullCodeGenerator::VisitRegExpLiteral(RegExpLiteral* expr) {
// eax = regexp literal clone.
__ mov(edi, Operand(ebp, JavaScriptFrameConstants::kFunctionOffset));
__ mov(ecx, FieldOperand(edi, JSFunction::kLiteralsOffset));
int literal_offset =
FixedArray::kHeaderSize + expr->literal_index() * kPointerSize;
int literal_offset = LiteralsArray::OffsetOfLiteralAt(expr->literal_index());
__ mov(ebx, FieldOperand(ecx, literal_offset));
__ cmp(ebx, isolate()->factory()->undefined_value());
__ j(not_equal, &materialized, Label::kNear);
Expand Down
3 changes: 1 addition & 2 deletions src/full-codegen/mips/full-codegen-mips.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1497,8 +1497,7 @@ void FullCodeGenerator::VisitRegExpLiteral(RegExpLiteral* expr) {
// a0 = RegExp literal clone
__ lw(a0, MemOperand(fp, JavaScriptFrameConstants::kFunctionOffset));
__ lw(t0, FieldMemOperand(a0, JSFunction::kLiteralsOffset));
int literal_offset =
FixedArray::kHeaderSize + expr->literal_index() * kPointerSize;
int literal_offset = LiteralsArray::OffsetOfLiteralAt(expr->literal_index());
__ lw(t1, FieldMemOperand(t0, literal_offset));
__ LoadRoot(at, Heap::kUndefinedValueRootIndex);
__ Branch(&materialized, ne, t1, Operand(at));
Expand Down
3 changes: 1 addition & 2 deletions src/full-codegen/mips64/full-codegen-mips64.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1495,8 +1495,7 @@ void FullCodeGenerator::VisitRegExpLiteral(RegExpLiteral* expr) {
// a0 = RegExp literal clone
__ ld(a0, MemOperand(fp, JavaScriptFrameConstants::kFunctionOffset));
__ ld(a4, FieldMemOperand(a0, JSFunction::kLiteralsOffset));
int literal_offset =
FixedArray::kHeaderSize + expr->literal_index() * kPointerSize;
int literal_offset = LiteralsArray::OffsetOfLiteralAt(expr->literal_index());
__ ld(a5, FieldMemOperand(a4, literal_offset));
__ LoadRoot(at, Heap::kUndefinedValueRootIndex);
__ Branch(&materialized, ne, a5, Operand(at));
Expand Down
3 changes: 1 addition & 2 deletions src/full-codegen/x64/full-codegen-x64.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1453,8 +1453,7 @@ void FullCodeGenerator::VisitRegExpLiteral(RegExpLiteral* expr) {
// rax = regexp literal clone.
__ movp(rdi, Operand(rbp, JavaScriptFrameConstants::kFunctionOffset));
__ movp(rcx, FieldOperand(rdi, JSFunction::kLiteralsOffset));
int literal_offset =
FixedArray::kHeaderSize + expr->literal_index() * kPointerSize;
int literal_offset = LiteralsArray::OffsetOfLiteralAt(expr->literal_index());
__ movp(rbx, FieldOperand(rcx, literal_offset));
__ CompareRoot(rbx, Heap::kUndefinedValueRootIndex);
__ j(not_equal, &materialized, Label::kNear);
Expand Down
15 changes: 8 additions & 7 deletions src/hydrogen.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5769,7 +5769,7 @@ void HOptimizedGraphBuilder::VisitRegExpLiteral(RegExpLiteral* expr) {
DCHECK(current_block() != NULL);
DCHECK(current_block()->HasPredecessor());
Handle<JSFunction> closure = function_state()->compilation_info()->closure();
Handle<FixedArray> literals(closure->literals());
Handle<LiteralsArray> literals(closure->literals());
HRegExpLiteral* instr = New<HRegExpLiteral>(literals,
expr->pattern(),
expr->flags(),
Expand Down Expand Up @@ -5865,8 +5865,8 @@ void HOptimizedGraphBuilder::VisitObjectLiteral(ObjectLiteral* expr) {

// Check whether to use fast or slow deep-copying for boilerplate.
int max_properties = kMaxFastLiteralProperties;
Handle<Object> literals_cell(closure->literals()->get(expr->literal_index()),
isolate());
Handle<Object> literals_cell(
closure->literals()->literal(expr->literal_index()), isolate());
Handle<AllocationSite> site;
Handle<JSObject> boilerplate;
if (!literals_cell->IsUndefined()) {
Expand All @@ -5884,7 +5884,7 @@ void HOptimizedGraphBuilder::VisitObjectLiteral(ObjectLiteral* expr) {
site_context.ExitScope(site, boilerplate);
} else {
NoObservableSideEffectsScope no_effects(this);
Handle<FixedArray> closure_literals(closure->literals(), isolate());
Handle<LiteralsArray> closure_literals(closure->literals(), isolate());
Handle<FixedArray> constant_properties = expr->constant_properties();
int literal_index = expr->literal_index();
int flags = expr->ComputeFlags(true);
Expand Down Expand Up @@ -5995,9 +5995,10 @@ void HOptimizedGraphBuilder::VisitArrayLiteral(ArrayLiteral* expr) {
HInstruction* literal;

Handle<AllocationSite> site;
Handle<FixedArray> literals(environment()->closure()->literals(), isolate());
Handle<LiteralsArray> literals(environment()->closure()->literals(),
isolate());
bool uninitialized = false;
Handle<Object> literals_cell(literals->get(expr->literal_index()),
Handle<Object> literals_cell(literals->literal(expr->literal_index()),
isolate());
Handle<JSObject> boilerplate_object;
if (literals_cell->IsUndefined()) {
Expand All @@ -6017,7 +6018,7 @@ void HOptimizedGraphBuilder::VisitArrayLiteral(ArrayLiteral* expr) {
return Bailout(kArrayBoilerplateCreationFailed);
}
creation_context.ExitScope(site, boilerplate_object);
literals->set(expr->literal_index(), *site);
literals->set_literal(expr->literal_index(), *site);

if (boilerplate_object->elements()->map() ==
isolate()->heap()->fixed_cow_array_map()) {
Expand Down
2 changes: 1 addition & 1 deletion src/ia32/lithium-codegen-ia32.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5281,7 +5281,7 @@ void LCodeGen::DoRegExpLiteral(LRegExpLiteral* instr) {
// eax = regexp literal clone.
// esi = context.
int literal_offset =
FixedArray::OffsetOfElementAt(instr->hydrogen()->literal_index());
LiteralsArray::OffsetOfLiteralAt(instr->hydrogen()->literal_index());
__ LoadHeapObject(ecx, instr->hydrogen()->literals());
__ mov(ebx, FieldOperand(ecx, literal_offset));
__ cmp(ebx, factory()->undefined_value());
Expand Down
2 changes: 1 addition & 1 deletion src/mips/lithium-codegen-mips.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5414,7 +5414,7 @@ void LCodeGen::DoRegExpLiteral(LRegExpLiteral* instr) {
// a0 = regexp literal clone.
// a2 and t0-t2 are used as temporaries.
int literal_offset =
FixedArray::OffsetOfElementAt(instr->hydrogen()->literal_index());
LiteralsArray::OffsetOfLiteralAt(instr->hydrogen()->literal_index());
__ li(t3, instr->hydrogen()->literals());
__ lw(a1, FieldMemOperand(t3, literal_offset));
__ LoadRoot(at, Heap::kUndefinedValueRootIndex);
Expand Down
2 changes: 1 addition & 1 deletion src/mips64/lithium-codegen-mips64.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5599,7 +5599,7 @@ void LCodeGen::DoRegExpLiteral(LRegExpLiteral* instr) {
// a0 = regexp literal clone.
// a2 and a4-a6 are used as temporaries.
int literal_offset =
FixedArray::OffsetOfElementAt(instr->hydrogen()->literal_index());
LiteralsArray::OffsetOfLiteralAt(instr->hydrogen()->literal_index());
__ li(a7, instr->hydrogen()->literals());
__ ld(a1, FieldMemOperand(a7, literal_offset));
__ LoadRoot(at, Heap::kUndefinedValueRootIndex);
Expand Down
58 changes: 55 additions & 3 deletions src/objects-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -730,6 +730,9 @@ bool Object::IsTransitionArray() const {
bool Object::IsTypeFeedbackVector() const { return IsFixedArray(); }


bool Object::IsLiteralsArray() const { return IsFixedArray(); }


bool Object::IsDeoptimizationInputData() const {
// Must be a fixed array.
if (!IsFixedArray()) return false;
Expand Down Expand Up @@ -3454,6 +3457,55 @@ void DeoptimizationOutputData::SetPcAndState(int index, Smi* offset) {
}


Object* LiteralsArray::get(int index) const { return FixedArray::get(index); }


void LiteralsArray::set(int index, Object* value) {
FixedArray::set(index, value);
}


void LiteralsArray::set(int index, Smi* value) {
FixedArray::set(index, value);
}


void LiteralsArray::set(int index, Object* value, WriteBarrierMode mode) {
FixedArray::set(index, value, mode);
}


LiteralsArray* LiteralsArray::cast(Object* object) {
SLOW_DCHECK(object->IsLiteralsArray());
return reinterpret_cast<LiteralsArray*>(object);
}


TypeFeedbackVector* LiteralsArray::feedback_vector() const {
return TypeFeedbackVector::cast(get(kVectorIndex));
}


void LiteralsArray::set_feedback_vector(TypeFeedbackVector* vector) {
set(kVectorIndex, vector);
}


Object* LiteralsArray::literal(int literal_index) const {
return get(kFirstLiteralIndex + literal_index);
}


void LiteralsArray::set_literal(int literal_index, Object* literal) {
set(kFirstLiteralIndex + literal_index, literal);
}


int LiteralsArray::literals_count() const {
return length() - kFirstLiteralIndex;
}


void HandlerTable::SetRangeStart(int index, int value) {
set(index * kRangeEntrySize + kRangeStartIndex, Smi::FromInt(value));
}
Expand Down Expand Up @@ -6258,13 +6310,13 @@ bool JSFunction::has_simple_parameters() {
}


FixedArray* JSFunction::literals() {
LiteralsArray* JSFunction::literals() {
DCHECK(!shared()->bound());
return literals_or_bindings();
return LiteralsArray::cast(literals_or_bindings());
}


void JSFunction::set_literals(FixedArray* literals) {
void JSFunction::set_literals(LiteralsArray* literals) {
DCHECK(!shared()->bound());
set_literals_or_bindings(literals);
}
Expand Down
17 changes: 15 additions & 2 deletions src/objects.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8782,6 +8782,19 @@ Handle<DeoptimizationOutputData> DeoptimizationOutputData::New(
}


// static
Handle<LiteralsArray> LiteralsArray::New(Isolate* isolate,
Handle<TypeFeedbackVector> vector,
int number_of_literals,
PretenureFlag pretenure) {
Handle<FixedArray> literals = isolate->factory()->NewFixedArray(
number_of_literals + kFirstLiteralIndex, pretenure);
Handle<LiteralsArray> casted_literals = Handle<LiteralsArray>::cast(literals);
casted_literals->set_feedback_vector(*vector);
return casted_literals;
}


int HandlerTable::LookupRange(int pc_offset, int* stack_depth_out,
CatchPrediction* prediction_out) {
int innermost_handler = -1, innermost_start = -1;
Expand Down Expand Up @@ -10191,7 +10204,7 @@ void SharedFunctionInfo::AddSharedCodeToOptimizedCodeMap(

void SharedFunctionInfo::AddToOptimizedCodeMap(
Handle<SharedFunctionInfo> shared, Handle<Context> native_context,
Handle<HeapObject> code, Handle<FixedArray> literals,
Handle<HeapObject> code, Handle<LiteralsArray> literals,
BailoutId osr_ast_id) {
Isolate* isolate = shared->GetIsolate();
DCHECK(*code == isolate->heap()->undefined_value() ||
Expand Down Expand Up @@ -11381,7 +11394,7 @@ CodeAndLiterals SharedFunctionInfo::SearchOptimizedCodeMap(
DCHECK_LE(entry + kEntryLength, code_map->length());
Object* code = code_map->get(entry + kCachedCodeOffset);
result = {code->IsUndefined() ? nullptr : Code::cast(code),
FixedArray::cast(code_map->get(entry + kLiteralsOffset))};
LiteralsArray::cast(code_map->get(entry + kLiteralsOffset))};
}
}
if (FLAG_trace_opt && !optimized_code_map()->IsSmi() &&
Expand Down
Loading

0 comments on commit d8cdd69

Please sign in to comment.