Commit 9e0f0a73 authored by bmeurer@chromium.org's avatar bmeurer@chromium.org

Get rid of ZoneScope completely.

There's no need to differentiate between an actual Zone and its
scope. Instead we bind the lifetime of the Zone memory to the
lifetime of the Zone itself, which is way easier to understand
than having to dig through the code looking for zone scopes.

Depends on https://codereview.chromium.org/17826004/

R=danno@chromium.org
BUG=

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

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@15337 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent 8e9b934e
...@@ -546,7 +546,6 @@ static bool DebuggerWantsEagerCompilation(CompilationInfo* info, ...@@ -546,7 +546,6 @@ static bool DebuggerWantsEagerCompilation(CompilationInfo* info,
static Handle<SharedFunctionInfo> MakeFunctionInfo(CompilationInfo* info) { static Handle<SharedFunctionInfo> MakeFunctionInfo(CompilationInfo* info) {
Isolate* isolate = info->isolate(); Isolate* isolate = info->isolate();
ZoneScope zone_scope(info->zone());
PostponeInterruptsScope postpone(isolate); PostponeInterruptsScope postpone(isolate);
ASSERT(!isolate->native_context().is_null()); ASSERT(!isolate->native_context().is_null());
...@@ -910,8 +909,6 @@ static bool InstallCodeFromOptimizedCodeMap(CompilationInfo* info) { ...@@ -910,8 +909,6 @@ static bool InstallCodeFromOptimizedCodeMap(CompilationInfo* info) {
bool Compiler::CompileLazy(CompilationInfo* info) { bool Compiler::CompileLazy(CompilationInfo* info) {
Isolate* isolate = info->isolate(); Isolate* isolate = info->isolate();
ZoneScope zone_scope(info->zone());
// The VM is in the COMPILER state until exiting this function. // The VM is in the COMPILER state until exiting this function.
VMState<COMPILER> state(isolate); VMState<COMPILER> state(isolate);
...@@ -1228,7 +1225,7 @@ void Compiler::RecordFunctionCompilation(Logger::LogEventsAndTags tag, ...@@ -1228,7 +1225,7 @@ void Compiler::RecordFunctionCompilation(Logger::LogEventsAndTags tag,
CompilationPhase::CompilationPhase(const char* name, CompilationPhase::CompilationPhase(const char* name,
Isolate* isolate, Isolate* isolate,
Zone* zone) Zone* zone)
: name_(name), isolate_(isolate), zone_scope_(zone) { : name_(name), isolate_(isolate), zone_(zone) {
if (FLAG_hydrogen_stats) { if (FLAG_hydrogen_stats) {
start_allocation_size_ = zone->allocation_size(); start_allocation_size_ = zone->allocation_size();
start_ticks_ = OS::Ticks(); start_ticks_ = OS::Ticks();
......
...@@ -441,22 +441,18 @@ class CompilationInfoWithZone: public CompilationInfo { ...@@ -441,22 +441,18 @@ class CompilationInfoWithZone: public CompilationInfo {
explicit CompilationInfoWithZone(Handle<Script> script) explicit CompilationInfoWithZone(Handle<Script> script)
: CompilationInfo(script, &zone_, &phase_zone_), : CompilationInfo(script, &zone_, &phase_zone_),
zone_(script->GetIsolate()), zone_(script->GetIsolate()),
zone_scope_(&zone_),
phase_zone_(script->GetIsolate()) {} phase_zone_(script->GetIsolate()) {}
explicit CompilationInfoWithZone(Handle<SharedFunctionInfo> shared_info) explicit CompilationInfoWithZone(Handle<SharedFunctionInfo> shared_info)
: CompilationInfo(shared_info, &zone_, &phase_zone_), : CompilationInfo(shared_info, &zone_, &phase_zone_),
zone_(shared_info->GetIsolate()), zone_(shared_info->GetIsolate()),
zone_scope_(&zone_),
phase_zone_(shared_info->GetIsolate()) {} phase_zone_(shared_info->GetIsolate()) {}
explicit CompilationInfoWithZone(Handle<JSFunction> closure) explicit CompilationInfoWithZone(Handle<JSFunction> closure)
: CompilationInfo(closure, &zone_, &phase_zone_), : CompilationInfo(closure, &zone_, &phase_zone_),
zone_(closure->GetIsolate()), zone_(closure->GetIsolate()),
zone_scope_(&zone_),
phase_zone_(closure->GetIsolate()) {} phase_zone_(closure->GetIsolate()) {}
CompilationInfoWithZone(HydrogenCodeStub* stub, Isolate* isolate) CompilationInfoWithZone(HydrogenCodeStub* stub, Isolate* isolate)
: CompilationInfo(stub, isolate, &zone_, &phase_zone_), : CompilationInfo(stub, isolate, &zone_, &phase_zone_),
zone_(isolate), zone_(isolate),
zone_scope_(&zone_),
phase_zone_(isolate) {} phase_zone_(isolate) {}
// Virtual destructor because a CompilationInfoWithZone has to exit the // Virtual destructor because a CompilationInfoWithZone has to exit the
...@@ -468,7 +464,6 @@ class CompilationInfoWithZone: public CompilationInfo { ...@@ -468,7 +464,6 @@ class CompilationInfoWithZone: public CompilationInfo {
private: private:
Zone zone_; Zone zone_;
ZoneScope zone_scope_;
Zone phase_zone_; Zone phase_zone_;
}; };
...@@ -643,12 +638,12 @@ class CompilationPhase BASE_EMBEDDED { ...@@ -643,12 +638,12 @@ class CompilationPhase BASE_EMBEDDED {
const char* name() const { return name_; } const char* name() const { return name_; }
Isolate* isolate() const { return isolate_; } Isolate* isolate() const { return isolate_; }
Zone* zone() const { return zone_scope_.zone(); } Zone* zone() const { return zone_; }
private: private:
const char* name_; const char* name_;
Isolate* isolate_; Isolate* isolate_;
ZoneScope zone_scope_; Zone* zone_;
unsigned start_allocation_size_; unsigned start_allocation_size_;
int64_t start_ticks_; int64_t start_ticks_;
......
...@@ -284,7 +284,7 @@ void Deoptimizer::GenerateDeoptimizationEntries(MacroAssembler* masm, ...@@ -284,7 +284,7 @@ void Deoptimizer::GenerateDeoptimizationEntries(MacroAssembler* masm,
void Deoptimizer::VisitAllOptimizedFunctionsForContext( void Deoptimizer::VisitAllOptimizedFunctionsForContext(
Context* context, OptimizedFunctionVisitor* visitor) { Context* context, OptimizedFunctionVisitor* visitor) {
Isolate* isolate = context->GetIsolate(); Isolate* isolate = context->GetIsolate();
ZoneScope zone_scope(isolate->runtime_zone()); Zone zone(isolate);
DisallowHeapAllocation no_allocation; DisallowHeapAllocation no_allocation;
ASSERT(context->IsNativeContext()); ASSERT(context->IsNativeContext());
...@@ -293,11 +293,11 @@ void Deoptimizer::VisitAllOptimizedFunctionsForContext( ...@@ -293,11 +293,11 @@ void Deoptimizer::VisitAllOptimizedFunctionsForContext(
// Create a snapshot of the optimized functions list. This is needed because // Create a snapshot of the optimized functions list. This is needed because
// visitors might remove more than one link from the list at once. // visitors might remove more than one link from the list at once.
ZoneList<JSFunction*> snapshot(1, isolate->runtime_zone()); ZoneList<JSFunction*> snapshot(1, &zone);
Object* element = context->OptimizedFunctionsListHead(); Object* element = context->OptimizedFunctionsListHead();
while (!element->IsUndefined()) { while (!element->IsUndefined()) {
JSFunction* element_function = JSFunction::cast(element); JSFunction* element_function = JSFunction::cast(element);
snapshot.Add(element_function, isolate->runtime_zone()); snapshot.Add(element_function, &zone);
element = element_function->next_function_link(); element = element_function->next_function_link();
} }
...@@ -420,11 +420,10 @@ void Deoptimizer::DeoptimizeFunction(JSFunction* function) { ...@@ -420,11 +420,10 @@ void Deoptimizer::DeoptimizeFunction(JSFunction* function) {
Context* context = function->context()->native_context(); Context* context = function->context()->native_context();
Isolate* isolate = context->GetIsolate(); Isolate* isolate = context->GetIsolate();
Object* undefined = isolate->heap()->undefined_value(); Object* undefined = isolate->heap()->undefined_value();
Zone* zone = isolate->runtime_zone(); Zone zone(isolate);
ZoneScope zone_scope(zone); ZoneList<Code*> codes(1, &zone);
ZoneList<Code*> codes(1, zone);
DeoptimizeWithMatchingCodeFilter filter(code); DeoptimizeWithMatchingCodeFilter filter(code);
PartitionOptimizedFunctions(context, &filter, &codes, zone, undefined); PartitionOptimizedFunctions(context, &filter, &codes, &zone, undefined);
ASSERT_EQ(1, codes.length()); ASSERT_EQ(1, codes.length());
DeoptimizeFunctionWithPreparedFunctionList( DeoptimizeFunctionWithPreparedFunctionList(
JSFunction::cast(codes.at(0)->deoptimizing_functions())); JSFunction::cast(codes.at(0)->deoptimizing_functions()));
...@@ -437,10 +436,9 @@ void Deoptimizer::DeoptimizeAllFunctionsForContext( ...@@ -437,10 +436,9 @@ void Deoptimizer::DeoptimizeAllFunctionsForContext(
ASSERT(context->IsNativeContext()); ASSERT(context->IsNativeContext());
Isolate* isolate = context->GetIsolate(); Isolate* isolate = context->GetIsolate();
Object* undefined = isolate->heap()->undefined_value(); Object* undefined = isolate->heap()->undefined_value();
Zone* zone = isolate->runtime_zone(); Zone zone(isolate);
ZoneScope zone_scope(zone); ZoneList<Code*> codes(1, &zone);
ZoneList<Code*> codes(1, zone); PartitionOptimizedFunctions(context, filter, &codes, &zone, undefined);
PartitionOptimizedFunctions(context, filter, &codes, zone, undefined);
for (int i = 0; i < codes.length(); ++i) { for (int i = 0; i < codes.length(); ++i) {
DeoptimizeFunctionWithPreparedFunctionList( DeoptimizeFunctionWithPreparedFunctionList(
JSFunction::cast(codes.at(i)->deoptimizing_functions())); JSFunction::cast(codes.at(i)->deoptimizing_functions()));
......
...@@ -1916,8 +1916,7 @@ static void UnregisterCodeEntry(JITCodeEntry* entry) { ...@@ -1916,8 +1916,7 @@ static void UnregisterCodeEntry(JITCodeEntry* entry) {
} }
static JITCodeEntry* CreateELFObject(CodeDescription* desc, Zone* zone) { static JITCodeEntry* CreateELFObject(CodeDescription* desc, Isolate* isolate) {
ZoneScope zone_scope(zone);
#ifdef __MACH_O #ifdef __MACH_O
MachO mach_o; MachO mach_o;
Writer w(&mach_o); Writer w(&mach_o);
...@@ -1930,11 +1929,12 @@ static JITCodeEntry* CreateELFObject(CodeDescription* desc, Zone* zone) { ...@@ -1930,11 +1929,12 @@ static JITCodeEntry* CreateELFObject(CodeDescription* desc, Zone* zone) {
mach_o.Write(&w, desc->CodeStart(), desc->CodeSize()); mach_o.Write(&w, desc->CodeStart(), desc->CodeSize());
#else #else
ELF elf(zone); Zone zone(isolate);
ELF elf(&zone);
Writer w(&elf); Writer w(&elf);
int text_section_index = elf.AddSection( int text_section_index = elf.AddSection(
new(zone) FullHeaderELFSection( new(&zone) FullHeaderELFSection(
".text", ".text",
ELFSection::TYPE_NOBITS, ELFSection::TYPE_NOBITS,
kCodeAlignment, kCodeAlignment,
...@@ -1942,11 +1942,11 @@ static JITCodeEntry* CreateELFObject(CodeDescription* desc, Zone* zone) { ...@@ -1942,11 +1942,11 @@ static JITCodeEntry* CreateELFObject(CodeDescription* desc, Zone* zone) {
0, 0,
desc->CodeSize(), desc->CodeSize(),
ELFSection::FLAG_ALLOC | ELFSection::FLAG_EXEC), ELFSection::FLAG_ALLOC | ELFSection::FLAG_EXEC),
zone); &zone);
CreateSymbolsTable(desc, zone, &elf, text_section_index); CreateSymbolsTable(desc, &zone, &elf, text_section_index);
CreateDWARFSections(desc, zone, &elf); CreateDWARFSections(desc, &zone, &elf);
elf.Write(&w); elf.Write(&w);
#endif #endif
...@@ -2083,8 +2083,9 @@ void GDBJITInterface::AddCode(const char* name, ...@@ -2083,8 +2083,9 @@ void GDBJITInterface::AddCode(const char* name,
} }
AddUnwindInfo(&code_desc); AddUnwindInfo(&code_desc);
Isolate* isolate = code->GetIsolate();
Zone* zone = code->GetIsolate()->runtime_zone(); Zone* zone = code->GetIsolate()->runtime_zone();
JITCodeEntry* entry = CreateELFObject(&code_desc, zone); JITCodeEntry* entry = CreateELFObject(&code_desc, isolate);
ASSERT(!IsLineInfoTagged(entry)); ASSERT(!IsLineInfoTagged(entry));
delete lineinfo; delete lineinfo;
......
...@@ -37,7 +37,6 @@ EnvironmentSlotLivenessAnalyzer::EnvironmentSlotLivenessAnalyzer( ...@@ -37,7 +37,6 @@ EnvironmentSlotLivenessAnalyzer::EnvironmentSlotLivenessAnalyzer(
HGraph* graph) HGraph* graph)
: graph_(graph), : graph_(graph),
zone_(graph->isolate()), zone_(graph->isolate()),
zone_scope_(&zone_),
block_count_(graph->blocks()->length()), block_count_(graph->blocks()->length()),
maximum_environment_size_(graph->maximum_environment_size()), maximum_environment_size_(graph->maximum_environment_size()),
collect_markers_(true), collect_markers_(true),
...@@ -147,7 +146,7 @@ void EnvironmentSlotLivenessAnalyzer::UpdateLivenessAtInstruction( ...@@ -147,7 +146,7 @@ void EnvironmentSlotLivenessAnalyzer::UpdateLivenessAtInstruction(
} }
if (collect_markers_) { if (collect_markers_) {
// Populate |markers_| list during the first pass. // Populate |markers_| list during the first pass.
markers_->Add(marker, &zone_); markers_->Add(marker, zone());
} }
break; break;
} }
......
...@@ -62,7 +62,6 @@ class EnvironmentSlotLivenessAnalyzer { ...@@ -62,7 +62,6 @@ class EnvironmentSlotLivenessAnalyzer {
// Use a dedicated Zone for this phase, with a ZoneScope to ensure it // Use a dedicated Zone for this phase, with a ZoneScope to ensure it
// gets freed. // gets freed.
Zone zone_; Zone zone_;
ZoneScope zone_scope_;
int block_count_; int block_count_;
......
...@@ -365,16 +365,15 @@ HGlobalValueNumberer::HGlobalValueNumberer(HGraph* graph, CompilationInfo* info) ...@@ -365,16 +365,15 @@ HGlobalValueNumberer::HGlobalValueNumberer(HGraph* graph, CompilationInfo* info)
: graph_(graph), : graph_(graph),
info_(info), info_(info),
removed_side_effects_(false), removed_side_effects_(false),
phase_zone_(info->phase_zone()), zone_(graph->isolate()),
phase_zone_scope_(phase_zone_), block_side_effects_(graph->blocks()->length(), zone()),
block_side_effects_(graph->blocks()->length(), phase_zone_), loop_side_effects_(graph->blocks()->length(), zone()),
loop_side_effects_(graph->blocks()->length(), phase_zone_), visited_on_paths_(zone(), graph->blocks()->length()) {
visited_on_paths_(phase_zone_, graph->blocks()->length()) {
ASSERT(!AllowHandleAllocation::IsAllowed()); ASSERT(!AllowHandleAllocation::IsAllowed());
block_side_effects_.AddBlock(GVNFlagSet(), graph_->blocks()->length(), block_side_effects_.AddBlock(GVNFlagSet(), graph_->blocks()->length(),
phase_zone_); zone());
loop_side_effects_.AddBlock(GVNFlagSet(), graph_->blocks()->length(), loop_side_effects_.AddBlock(GVNFlagSet(), graph_->blocks()->length(),
phase_zone_); zone());
} }
bool HGlobalValueNumberer::Analyze() { bool HGlobalValueNumberer::Analyze() {
...@@ -758,9 +757,9 @@ class GvnBasicBlockState: public ZoneObject { ...@@ -758,9 +757,9 @@ class GvnBasicBlockState: public ZoneObject {
// GvnBasicBlockState instances. // GvnBasicBlockState instances.
void HGlobalValueNumberer::AnalyzeGraph() { void HGlobalValueNumberer::AnalyzeGraph() {
HBasicBlock* entry_block = graph_->entry_block(); HBasicBlock* entry_block = graph_->entry_block();
HValueMap* entry_map = new(phase_zone()) HValueMap(phase_zone()); HValueMap* entry_map = new(zone()) HValueMap(zone());
GvnBasicBlockState* current = GvnBasicBlockState* current =
GvnBasicBlockState::CreateEntry(phase_zone(), entry_block, entry_map); GvnBasicBlockState::CreateEntry(zone(), entry_block, entry_map);
while (current != NULL) { while (current != NULL) {
HBasicBlock* block = current->block(); HBasicBlock* block = current->block();
...@@ -802,7 +801,7 @@ void HGlobalValueNumberer::AnalyzeGraph() { ...@@ -802,7 +801,7 @@ void HGlobalValueNumberer::AnalyzeGraph() {
if (instr->HasSideEffects()) removed_side_effects_ = true; if (instr->HasSideEffects()) removed_side_effects_ = true;
instr->DeleteAndReplaceWith(other); instr->DeleteAndReplaceWith(other);
} else { } else {
map->Add(instr, phase_zone()); map->Add(instr, zone());
} }
} }
if (instr->IsLinked() && if (instr->IsLinked() &&
...@@ -828,7 +827,7 @@ void HGlobalValueNumberer::AnalyzeGraph() { ...@@ -828,7 +827,7 @@ void HGlobalValueNumberer::AnalyzeGraph() {
HBasicBlock* dominator_block; HBasicBlock* dominator_block;
GvnBasicBlockState* next = GvnBasicBlockState* next =
current->next_in_dominator_tree_traversal(phase_zone(), current->next_in_dominator_tree_traversal(zone(),
&dominator_block); &dominator_block);
if (next != NULL) { if (next != NULL) {
......
...@@ -100,14 +100,13 @@ class HGlobalValueNumberer BASE_EMBEDDED { ...@@ -100,14 +100,13 @@ class HGlobalValueNumberer BASE_EMBEDDED {
HGraph* graph() { return graph_; } HGraph* graph() { return graph_; }
CompilationInfo* info() { return info_; } CompilationInfo* info() { return info_; }
Zone* phase_zone() const { return info_->phase_zone(); } Zone* zone() { return &zone_; }
HGraph* graph_; HGraph* graph_;
CompilationInfo* info_; CompilationInfo* info_;
bool removed_side_effects_; bool removed_side_effects_;
Zone* phase_zone_; Zone zone_;
ZoneScope phase_zone_scope_;
// A map of block IDs to their side effects. // A map of block IDs to their side effects.
ZoneList<GVNFlagSet> block_side_effects_; ZoneList<GVNFlagSet> block_side_effects_;
......
...@@ -1738,7 +1738,6 @@ Isolate::Isolate() ...@@ -1738,7 +1738,6 @@ Isolate::Isolate()
descriptor_lookup_cache_(NULL), descriptor_lookup_cache_(NULL),
handle_scope_implementer_(NULL), handle_scope_implementer_(NULL),
unicode_cache_(NULL), unicode_cache_(NULL),
runtime_zone_(this),
in_use_list_(0), in_use_list_(0),
free_list_(0), free_list_(0),
preallocated_storage_preallocated_(false), preallocated_storage_preallocated_(false),
...@@ -1935,9 +1934,6 @@ void Isolate::SetIsolateThreadLocals(Isolate* isolate, ...@@ -1935,9 +1934,6 @@ void Isolate::SetIsolateThreadLocals(Isolate* isolate,
Isolate::~Isolate() { Isolate::~Isolate() {
TRACE_ISOLATE(destructor); TRACE_ISOLATE(destructor);
// Has to be called while counters_ are still alive.
runtime_zone_.DeleteKeptSegment();
delete[] assembler_spare_buffer_; delete[] assembler_spare_buffer_;
assembler_spare_buffer_ = NULL; assembler_spare_buffer_ = NULL;
...@@ -2114,7 +2110,7 @@ bool Isolate::Init(Deserializer* des) { ...@@ -2114,7 +2110,7 @@ bool Isolate::Init(Deserializer* des) {
global_handles_ = new GlobalHandles(this); global_handles_ = new GlobalHandles(this);
bootstrapper_ = new Bootstrapper(this); bootstrapper_ = new Bootstrapper(this);
handle_scope_implementer_ = new HandleScopeImplementer(this); handle_scope_implementer_ = new HandleScopeImplementer(this);
stub_cache_ = new StubCache(this, runtime_zone()); stub_cache_ = new StubCache(this);
regexp_stack_ = new RegExpStack(); regexp_stack_ = new RegExpStack();
regexp_stack_->isolate_ = this; regexp_stack_->isolate_ = this;
date_cache_ = new DateCache(); date_cache_ = new DateCache();
......
...@@ -892,7 +892,6 @@ class Isolate { ...@@ -892,7 +892,6 @@ class Isolate {
ASSERT(handle_scope_implementer_); ASSERT(handle_scope_implementer_);
return handle_scope_implementer_; return handle_scope_implementer_;
} }
Zone* runtime_zone() { return &runtime_zone_; }
UnicodeCache* unicode_cache() { UnicodeCache* unicode_cache() {
return unicode_cache_; return unicode_cache_;
...@@ -1260,7 +1259,6 @@ class Isolate { ...@@ -1260,7 +1259,6 @@ class Isolate {
v8::ImplementationUtilities::HandleScopeData handle_scope_data_; v8::ImplementationUtilities::HandleScopeData handle_scope_data_;
HandleScopeImplementer* handle_scope_implementer_; HandleScopeImplementer* handle_scope_implementer_;
UnicodeCache* unicode_cache_; UnicodeCache* unicode_cache_;
Zone runtime_zone_;
PreallocatedStorage in_use_list_; PreallocatedStorage in_use_list_;
PreallocatedStorage free_list_; PreallocatedStorage free_list_;
bool preallocated_storage_preallocated_; bool preallocated_storage_preallocated_;
......
...@@ -43,15 +43,33 @@ namespace internal { ...@@ -43,15 +43,33 @@ namespace internal {
template <bool seq_ascii> template <bool seq_ascii>
class JsonParser BASE_EMBEDDED { class JsonParser BASE_EMBEDDED {
public: public:
static Handle<Object> Parse(Handle<String> source, Zone* zone) { static Handle<Object> Parse(Handle<String> source) {
return JsonParser().ParseJson(source, zone); return JsonParser(source).ParseJson();
} }
static const int kEndOfString = -1; static const int kEndOfString = -1;
private: private:
explicit JsonParser(Handle<String> source)
: source_(source),
source_length_(source->length()),
isolate_(source->map()->GetHeap()->isolate()),
factory_(isolate_->factory()),
zone_(isolate_),
object_constructor_(isolate_->native_context()->object_function(),
isolate_),
position_(-1) {
FlattenString(source_);
pretenure_ = (source_length_ >= kPretenureTreshold) ? TENURED : NOT_TENURED;
// Optimized fast case where we only have ASCII characters.
if (seq_ascii) {
seq_source_ = Handle<SeqOneByteString>::cast(source_);
}
}
// Parse a string containing a single JSON value. // Parse a string containing a single JSON value.
Handle<Object> ParseJson(Handle<String> source, Zone* zone); Handle<Object> ParseJson();
inline void Advance() { inline void Advance() {
position_++; position_++;
...@@ -179,13 +197,14 @@ class JsonParser BASE_EMBEDDED { ...@@ -179,13 +197,14 @@ class JsonParser BASE_EMBEDDED {
inline Isolate* isolate() { return isolate_; } inline Isolate* isolate() { return isolate_; }
inline Factory* factory() { return factory_; } inline Factory* factory() { return factory_; }
inline Handle<JSFunction> object_constructor() { return object_constructor_; } inline Handle<JSFunction> object_constructor() { return object_constructor_; }
inline Zone* zone() const { return zone_; }
static const int kInitialSpecialStringLength = 1024; static const int kInitialSpecialStringLength = 1024;
static const int kPretenureTreshold = 100 * 1024; static const int kPretenureTreshold = 100 * 1024;
private: private:
Zone* zone() { return &zone_; }
Handle<String> source_; Handle<String> source_;
int source_length_; int source_length_;
Handle<SeqOneByteString> seq_source_; Handle<SeqOneByteString> seq_source_;
...@@ -193,32 +212,14 @@ class JsonParser BASE_EMBEDDED { ...@@ -193,32 +212,14 @@ class JsonParser BASE_EMBEDDED {
PretenureFlag pretenure_; PretenureFlag pretenure_;
Isolate* isolate_; Isolate* isolate_;
Factory* factory_; Factory* factory_;
Zone zone_;
Handle<JSFunction> object_constructor_; Handle<JSFunction> object_constructor_;
uc32 c0_; uc32 c0_;
int position_; int position_;
Zone* zone_;
}; };
template <bool seq_ascii> template <bool seq_ascii>
Handle<Object> JsonParser<seq_ascii>::ParseJson(Handle<String> source, Handle<Object> JsonParser<seq_ascii>::ParseJson() {
Zone* zone) {
isolate_ = source->map()->GetHeap()->isolate();
factory_ = isolate_->factory();
object_constructor_ = Handle<JSFunction>(
isolate()->native_context()->object_function(), isolate());
zone_ = zone;
FlattenString(source);
source_ = source;
source_length_ = source_->length();
pretenure_ = (source_length_ >= kPretenureTreshold) ? TENURED : NOT_TENURED;
// Optimized fast case where we only have ASCII characters.
if (seq_ascii) {
seq_source_ = Handle<SeqOneByteString>::cast(source_);
}
// Set initial position right before the string.
position_ = -1;
// Advance to the first character (possibly EOS) // Advance to the first character (possibly EOS)
AdvanceSkipWhitespace(); AdvanceSkipWhitespace();
Handle<Object> result = ParseJsonValue(); Handle<Object> result = ParseJsonValue();
...@@ -264,7 +265,7 @@ Handle<Object> JsonParser<seq_ascii>::ParseJson(Handle<String> source, ...@@ -264,7 +265,7 @@ Handle<Object> JsonParser<seq_ascii>::ParseJson(Handle<String> source,
break; break;
} }
MessageLocation location(factory->NewScript(source), MessageLocation location(factory->NewScript(source_),
position_, position_,
position_ + 1); position_ + 1);
Handle<Object> result = factory->NewSyntaxError(message, array); Handle<Object> result = factory->NewSyntaxError(message, array);
...@@ -323,7 +324,6 @@ Handle<Object> JsonParser<seq_ascii>::ParseJsonObject() { ...@@ -323,7 +324,6 @@ Handle<Object> JsonParser<seq_ascii>::ParseJsonObject() {
Handle<JSObject> json_object = Handle<JSObject> json_object =
factory()->NewJSObject(object_constructor(), pretenure_); factory()->NewJSObject(object_constructor(), pretenure_);
Handle<Map> map(json_object->map()); Handle<Map> map(json_object->map());
ZoneScope zone_scope(zone());
ZoneList<Handle<Object> > properties(8, zone()); ZoneList<Handle<Object> > properties(8, zone());
ASSERT_EQ(c0_, '{'); ASSERT_EQ(c0_, '{');
...@@ -469,7 +469,6 @@ Handle<Object> JsonParser<seq_ascii>::ParseJsonObject() { ...@@ -469,7 +469,6 @@ Handle<Object> JsonParser<seq_ascii>::ParseJsonObject() {
template <bool seq_ascii> template <bool seq_ascii>
Handle<Object> JsonParser<seq_ascii>::ParseJsonArray() { Handle<Object> JsonParser<seq_ascii>::ParseJsonArray() {
HandleScope scope(isolate()); HandleScope scope(isolate());
ZoneScope zone_scope(zone());
ZoneList<Handle<Object> > elements(4, zone()); ZoneList<Handle<Object> > elements(4, zone());
ASSERT_EQ(c0_, '['); ASSERT_EQ(c0_, '[');
......
...@@ -168,10 +168,9 @@ static bool HasFewDifferentCharacters(Handle<String> pattern) { ...@@ -168,10 +168,9 @@ static bool HasFewDifferentCharacters(Handle<String> pattern) {
Handle<Object> RegExpImpl::Compile(Handle<JSRegExp> re, Handle<Object> RegExpImpl::Compile(Handle<JSRegExp> re,
Handle<String> pattern, Handle<String> pattern,
Handle<String> flag_str, Handle<String> flag_str) {
Zone* zone) {
ZoneScope zone_scope(zone);
Isolate* isolate = re->GetIsolate(); Isolate* isolate = re->GetIsolate();
Zone zone(isolate);
JSRegExp::Flags flags = RegExpFlagsFromString(flag_str); JSRegExp::Flags flags = RegExpFlagsFromString(flag_str);
CompilationCache* compilation_cache = isolate->compilation_cache(); CompilationCache* compilation_cache = isolate->compilation_cache();
Handle<FixedArray> cached = compilation_cache->LookupRegExp(pattern, flags); Handle<FixedArray> cached = compilation_cache->LookupRegExp(pattern, flags);
...@@ -188,7 +187,7 @@ Handle<Object> RegExpImpl::Compile(Handle<JSRegExp> re, ...@@ -188,7 +187,7 @@ Handle<Object> RegExpImpl::Compile(Handle<JSRegExp> re,
RegExpCompileData parse_result; RegExpCompileData parse_result;
FlatStringReader reader(isolate, pattern); FlatStringReader reader(isolate, pattern);
if (!RegExpParser::ParseRegExp(&reader, flags.is_multiline(), if (!RegExpParser::ParseRegExp(&reader, flags.is_multiline(),
&parse_result, zone)) { &parse_result, &zone)) {
// Throw an exception if we fail to parse the pattern. // Throw an exception if we fail to parse the pattern.
ThrowRegExpException(re, ThrowRegExpException(re,
pattern, pattern,
...@@ -410,7 +409,7 @@ bool RegExpImpl::CompileIrregexp(Handle<JSRegExp> re, ...@@ -410,7 +409,7 @@ bool RegExpImpl::CompileIrregexp(Handle<JSRegExp> re,
bool is_ascii) { bool is_ascii) {
// Compile the RegExp. // Compile the RegExp.
Isolate* isolate = re->GetIsolate(); Isolate* isolate = re->GetIsolate();
ZoneScope zone_scope(isolate->runtime_zone()); Zone zone(isolate);
PostponeInterruptsScope postpone(isolate); PostponeInterruptsScope postpone(isolate);
// If we had a compilation error the last time this is saved at the // If we had a compilation error the last time this is saved at the
// saved code index. // saved code index.
...@@ -441,10 +440,9 @@ bool RegExpImpl::CompileIrregexp(Handle<JSRegExp> re, ...@@ -441,10 +440,9 @@ bool RegExpImpl::CompileIrregexp(Handle<JSRegExp> re,
if (!pattern->IsFlat()) FlattenString(pattern); if (!pattern->IsFlat()) FlattenString(pattern);
RegExpCompileData compile_data; RegExpCompileData compile_data;
FlatStringReader reader(isolate, pattern); FlatStringReader reader(isolate, pattern);
Zone* zone = isolate->runtime_zone();
if (!RegExpParser::ParseRegExp(&reader, flags.is_multiline(), if (!RegExpParser::ParseRegExp(&reader, flags.is_multiline(),
&compile_data, &compile_data,
zone)) { &zone)) {
// Throw an exception if we fail to parse the pattern. // Throw an exception if we fail to parse the pattern.
// THIS SHOULD NOT HAPPEN. We already pre-parsed it successfully once. // THIS SHOULD NOT HAPPEN. We already pre-parsed it successfully once.
ThrowRegExpException(re, ThrowRegExpException(re,
...@@ -461,7 +459,7 @@ bool RegExpImpl::CompileIrregexp(Handle<JSRegExp> re, ...@@ -461,7 +459,7 @@ bool RegExpImpl::CompileIrregexp(Handle<JSRegExp> re,
pattern, pattern,
sample_subject, sample_subject,
is_ascii, is_ascii,
zone); &zone);
if (result.error_message != NULL) { if (result.error_message != NULL) {
// Unable to compile regexp. // Unable to compile regexp.
Handle<String> error_message = Handle<String> error_message =
......
...@@ -71,8 +71,7 @@ class RegExpImpl { ...@@ -71,8 +71,7 @@ class RegExpImpl {
// Returns false if compilation fails. // Returns false if compilation fails.
static Handle<Object> Compile(Handle<JSRegExp> re, static Handle<Object> Compile(Handle<JSRegExp> re,
Handle<String> pattern, Handle<String> pattern,
Handle<String> flags, Handle<String> flags);
Zone* zone);
// See ECMA-262 section 15.10.6.2. // See ECMA-262 section 15.10.6.2.
// This function calls the garbage collector if necessary. // This function calls the garbage collector if necessary.
......
...@@ -1832,11 +1832,11 @@ class MultipleFunctionTarget { ...@@ -1832,11 +1832,11 @@ class MultipleFunctionTarget {
// Drops all call frame matched by target and all frames above them. // Drops all call frame matched by target and all frames above them.
template<typename TARGET> template<typename TARGET>
static const char* DropActivationsInActiveThreadImpl( static const char* DropActivationsInActiveThreadImpl(
TARGET& target, bool do_drop, Zone* zone) { TARGET& target, bool do_drop) {
Isolate* isolate = Isolate::Current(); Isolate* isolate = Isolate::Current();
Debug* debug = isolate->debug(); Debug* debug = isolate->debug();
ZoneScope scope(zone); Zone zone(isolate);
Vector<StackFrame*> frames = CreateStackMap(isolate, zone); Vector<StackFrame*> frames = CreateStackMap(isolate, &zone);
int top_frame_index = -1; int top_frame_index = -1;
...@@ -1928,12 +1928,11 @@ static const char* DropActivationsInActiveThreadImpl( ...@@ -1928,12 +1928,11 @@ static const char* DropActivationsInActiveThreadImpl(
// Fills result array with statuses of functions. Modifies the stack // Fills result array with statuses of functions. Modifies the stack
// removing all listed function if possible and if do_drop is true. // removing all listed function if possible and if do_drop is true.
static const char* DropActivationsInActiveThread( static const char* DropActivationsInActiveThread(
Handle<JSArray> shared_info_array, Handle<JSArray> result, bool do_drop, Handle<JSArray> shared_info_array, Handle<JSArray> result, bool do_drop) {
Zone* zone) {
MultipleFunctionTarget target(shared_info_array, result); MultipleFunctionTarget target(shared_info_array, result);
const char* message = const char* message =
DropActivationsInActiveThreadImpl(target, do_drop, zone); DropActivationsInActiveThreadImpl(target, do_drop);
if (message) { if (message) {
return message; return message;
} }
...@@ -1980,7 +1979,7 @@ class InactiveThreadActivationsChecker : public ThreadVisitor { ...@@ -1980,7 +1979,7 @@ class InactiveThreadActivationsChecker : public ThreadVisitor {
Handle<JSArray> LiveEdit::CheckAndDropActivations( Handle<JSArray> LiveEdit::CheckAndDropActivations(
Handle<JSArray> shared_info_array, bool do_drop, Zone* zone) { Handle<JSArray> shared_info_array, bool do_drop) {
Isolate* isolate = shared_info_array->GetIsolate(); Isolate* isolate = shared_info_array->GetIsolate();
int len = GetArrayLength(shared_info_array); int len = GetArrayLength(shared_info_array);
...@@ -2006,7 +2005,7 @@ Handle<JSArray> LiveEdit::CheckAndDropActivations( ...@@ -2006,7 +2005,7 @@ Handle<JSArray> LiveEdit::CheckAndDropActivations(
// Try to drop activations from the current stack. // Try to drop activations from the current stack.
const char* error_message = const char* error_message =
DropActivationsInActiveThread(shared_info_array, result, do_drop, zone); DropActivationsInActiveThread(shared_info_array, result, do_drop);
if (error_message != NULL) { if (error_message != NULL) {
// Add error message as an array extra element. // Add error message as an array extra element.
Vector<const char> vector_message(error_message, StrLength(error_message)); Vector<const char> vector_message(error_message, StrLength(error_message));
...@@ -2047,10 +2046,10 @@ class SingleFrameTarget { ...@@ -2047,10 +2046,10 @@ class SingleFrameTarget {
// Finds a drops required frame and all frames above. // Finds a drops required frame and all frames above.
// Returns error message or NULL. // Returns error message or NULL.
const char* LiveEdit::RestartFrame(JavaScriptFrame* frame, Zone* zone) { const char* LiveEdit::RestartFrame(JavaScriptFrame* frame) {
SingleFrameTarget target(frame); SingleFrameTarget target(frame);
const char* result = DropActivationsInActiveThreadImpl(target, true, zone); const char* result = DropActivationsInActiveThreadImpl(target, true);
if (result != NULL) { if (result != NULL) {
return result; return result;
} }
......
...@@ -121,11 +121,11 @@ class LiveEdit : AllStatic { ...@@ -121,11 +121,11 @@ class LiveEdit : AllStatic {
// has restart the lowest found frames and drops all other frames above // has restart the lowest found frames and drops all other frames above
// if possible and if do_drop is true. // if possible and if do_drop is true.
static Handle<JSArray> CheckAndDropActivations( static Handle<JSArray> CheckAndDropActivations(
Handle<JSArray> shared_info_array, bool do_drop, Zone* zone); Handle<JSArray> shared_info_array, bool do_drop);
// Restarts the call frame and completely drops all frames above it. // Restarts the call frame and completely drops all frames above it.
// Return error message or NULL. // Return error message or NULL.
static const char* RestartFrame(JavaScriptFrame* frame, Zone* zone); static const char* RestartFrame(JavaScriptFrame* frame);
// A copy of this is in liveedit-debugger.js. // A copy of this is in liveedit-debugger.js.
enum FunctionPatchabilityStatus { enum FunctionPatchabilityStatus {
......
...@@ -1700,7 +1700,7 @@ RUNTIME_FUNCTION(MaybeObject*, Runtime_RegExpCompile) { ...@@ -1700,7 +1700,7 @@ RUNTIME_FUNCTION(MaybeObject*, Runtime_RegExpCompile) {
CONVERT_ARG_HANDLE_CHECKED(String, pattern, 1); CONVERT_ARG_HANDLE_CHECKED(String, pattern, 1);
CONVERT_ARG_HANDLE_CHECKED(String, flags, 2); CONVERT_ARG_HANDLE_CHECKED(String, flags, 2);
Handle<Object> result = Handle<Object> result =
RegExpImpl::Compile(re, pattern, flags, isolate->runtime_zone()); RegExpImpl::Compile(re, pattern, flags);
if (result.is_null()) return Failure::Exception(); if (result.is_null()) return Failure::Exception();
return *result; return *result;
} }
...@@ -3600,9 +3600,8 @@ MUST_USE_RESULT static MaybeObject* StringReplaceGlobalAtomRegExpWithString( ...@@ -3600,9 +3600,8 @@ MUST_USE_RESULT static MaybeObject* StringReplaceGlobalAtomRegExpWithString(
ASSERT(subject->IsFlat()); ASSERT(subject->IsFlat());
ASSERT(replacement->IsFlat()); ASSERT(replacement->IsFlat());
Zone* zone = isolate->runtime_zone(); Zone zone(isolate);
ZoneScope zone_space(zone); ZoneList<int> indices(8, &zone);
ZoneList<int> indices(8, zone);
ASSERT_EQ(JSRegExp::ATOM, pattern_regexp->TypeTag()); ASSERT_EQ(JSRegExp::ATOM, pattern_regexp->TypeTag());
String* pattern = String* pattern =
String::cast(pattern_regexp->DataAt(JSRegExp::kAtomPatternIndex)); String::cast(pattern_regexp->DataAt(JSRegExp::kAtomPatternIndex));
...@@ -3611,7 +3610,7 @@ MUST_USE_RESULT static MaybeObject* StringReplaceGlobalAtomRegExpWithString( ...@@ -3611,7 +3610,7 @@ MUST_USE_RESULT static MaybeObject* StringReplaceGlobalAtomRegExpWithString(
int replacement_len = replacement->length(); int replacement_len = replacement->length();
FindStringIndicesDispatch( FindStringIndicesDispatch(
isolate, *subject, pattern, &indices, 0xffffffff, zone); isolate, *subject, pattern, &indices, 0xffffffff, &zone);
int matches = indices.length(); int matches = indices.length();
if (matches == 0) return *subject; if (matches == 0) return *subject;
...@@ -3687,9 +3686,8 @@ MUST_USE_RESULT static MaybeObject* StringReplaceGlobalRegExpWithString( ...@@ -3687,9 +3686,8 @@ MUST_USE_RESULT static MaybeObject* StringReplaceGlobalRegExpWithString(
int subject_length = subject->length(); int subject_length = subject->length();
// CompiledReplacement uses zone allocation. // CompiledReplacement uses zone allocation.
Zone* zone = isolate->runtime_zone(); Zone zone(isolate);
ZoneScope zonescope(zone); CompiledReplacement compiled_replacement(&zone);
CompiledReplacement compiled_replacement(zone);
bool simple_replace = compiled_replacement.Compile(replacement, bool simple_replace = compiled_replacement.Compile(replacement,
capture_count, capture_count,
subject_length); subject_length);
...@@ -4222,15 +4220,14 @@ RUNTIME_FUNCTION(MaybeObject*, Runtime_StringMatch) { ...@@ -4222,15 +4220,14 @@ RUNTIME_FUNCTION(MaybeObject*, Runtime_StringMatch) {
int capture_count = regexp->CaptureCount(); int capture_count = regexp->CaptureCount();
Zone* zone = isolate->runtime_zone(); Zone zone(isolate);
ZoneScope zone_space(zone); ZoneList<int> offsets(8, &zone);
ZoneList<int> offsets(8, zone);
while (true) { while (true) {
int32_t* match = global_cache.FetchNext(); int32_t* match = global_cache.FetchNext();
if (match == NULL) break; if (match == NULL) break;
offsets.Add(match[0], zone); // start offsets.Add(match[0], &zone); // start
offsets.Add(match[1], zone); // end offsets.Add(match[1], &zone); // end
} }
if (global_cache.HasException()) return Failure::Exception(); if (global_cache.HasException()) return Failure::Exception();
...@@ -6315,18 +6312,18 @@ RUNTIME_FUNCTION(MaybeObject*, Runtime_StringSplit) { ...@@ -6315,18 +6312,18 @@ RUNTIME_FUNCTION(MaybeObject*, Runtime_StringSplit) {
static const int kMaxInitialListCapacity = 16; static const int kMaxInitialListCapacity = 16;
Zone* zone = isolate->runtime_zone(); Zone zone(isolate);
ZoneScope scope(zone);
// Find (up to limit) indices of separator and end-of-string in subject // Find (up to limit) indices of separator and end-of-string in subject
int initial_capacity = Min<uint32_t>(kMaxInitialListCapacity, limit); int initial_capacity = Min<uint32_t>(kMaxInitialListCapacity, limit);
ZoneList<int> indices(initial_capacity, zone); ZoneList<int> indices(initial_capacity, &zone);
if (!pattern->IsFlat()) FlattenString(pattern); if (!pattern->IsFlat()) FlattenString(pattern);
FindStringIndicesDispatch(isolate, *subject, *pattern, &indices, limit, zone); FindStringIndicesDispatch(isolate, *subject, *pattern,
&indices, limit, &zone);
if (static_cast<uint32_t>(indices.length()) < limit) { if (static_cast<uint32_t>(indices.length()) < limit) {
indices.Add(subject_length, zone); indices.Add(subject_length, &zone);
} }
// The list indices now contains the end of each part to create. // The list indices now contains the end of each part to create.
...@@ -9318,14 +9315,13 @@ RUNTIME_FUNCTION(MaybeObject*, Runtime_ParseJson) { ...@@ -9318,14 +9315,13 @@ RUNTIME_FUNCTION(MaybeObject*, Runtime_ParseJson) {
ASSERT_EQ(1, args.length()); ASSERT_EQ(1, args.length());
CONVERT_ARG_HANDLE_CHECKED(String, source, 0); CONVERT_ARG_HANDLE_CHECKED(String, source, 0);
Zone* zone = isolate->runtime_zone();
source = Handle<String>(source->TryFlattenGetString()); source = Handle<String>(source->TryFlattenGetString());
// Optimized fast case where we only have ASCII characters. // Optimized fast case where we only have ASCII characters.
Handle<Object> result; Handle<Object> result;
if (source->IsSeqOneByteString()) { if (source->IsSeqOneByteString()) {
result = JsonParser<true>::Parse(source, zone); result = JsonParser<true>::Parse(source);
} else { } else {
result = JsonParser<false>::Parse(source, zone); result = JsonParser<false>::Parse(source);
} }
if (result.is_null()) { if (result.is_null()) {
// Syntax error or stack overflow in scanner. // Syntax error or stack overflow in scanner.
...@@ -13120,8 +13116,7 @@ RUNTIME_FUNCTION(MaybeObject*, Runtime_LiveEditCheckAndDropActivations) { ...@@ -13120,8 +13116,7 @@ RUNTIME_FUNCTION(MaybeObject*, Runtime_LiveEditCheckAndDropActivations) {
CONVERT_ARG_HANDLE_CHECKED(JSArray, shared_array, 0); CONVERT_ARG_HANDLE_CHECKED(JSArray, shared_array, 0);
CONVERT_BOOLEAN_ARG_CHECKED(do_drop, 1); CONVERT_BOOLEAN_ARG_CHECKED(do_drop, 1);
return *LiveEdit::CheckAndDropActivations(shared_array, do_drop, return *LiveEdit::CheckAndDropActivations(shared_array, do_drop);
isolate->runtime_zone());
} }
// Compares 2 strings line-by-line, then token-wise and returns diff in form // Compares 2 strings line-by-line, then token-wise and returns diff in form
...@@ -13169,8 +13164,7 @@ RUNTIME_FUNCTION(MaybeObject*, Runtime_LiveEditRestartFrame) { ...@@ -13169,8 +13164,7 @@ RUNTIME_FUNCTION(MaybeObject*, Runtime_LiveEditRestartFrame) {
} }
if (it.done()) return heap->undefined_value(); if (it.done()) return heap->undefined_value();
const char* error_message = const char* error_message = LiveEdit::RestartFrame(it.frame());
LiveEdit::RestartFrame(it.frame(), isolate->runtime_zone());
if (error_message) { if (error_message) {
return *(isolate->factory()->InternalizeUtf8String(error_message)); return *(isolate->factory()->InternalizeUtf8String(error_message));
} }
......
...@@ -43,7 +43,7 @@ namespace internal { ...@@ -43,7 +43,7 @@ namespace internal {
// StubCache implementation. // StubCache implementation.
StubCache::StubCache(Isolate* isolate, Zone* zone) StubCache::StubCache(Isolate* isolate)
: isolate_(isolate) { : isolate_(isolate) {
ASSERT(isolate == Isolate::Current()); ASSERT(isolate == Isolate::Current());
} }
......
...@@ -367,7 +367,7 @@ class StubCache { ...@@ -367,7 +367,7 @@ class StubCache {
Factory* factory() { return isolate()->factory(); } Factory* factory() { return isolate()->factory(); }
private: private:
StubCache(Isolate* isolate, Zone* zone); explicit StubCache(Isolate* isolate);
Handle<Code> ComputeCallInitialize(int argc, Handle<Code> ComputeCallInitialize(int argc,
RelocInfo::Mode mode, RelocInfo::Mode mode,
......
...@@ -40,7 +40,6 @@ namespace internal { ...@@ -40,7 +40,6 @@ namespace internal {
inline void* Zone::New(int size) { inline void* Zone::New(int size) {
ASSERT(scope_nesting_ > 0);
// Round up the requested size to fit the alignment. // Round up the requested size to fit the alignment.
size = RoundUp(size, kAlignment); size = RoundUp(size, kAlignment);
...@@ -110,17 +109,6 @@ void* ZoneList<T>::operator new(size_t size, Zone* zone) { ...@@ -110,17 +109,6 @@ void* ZoneList<T>::operator new(size_t size, Zone* zone) {
} }
ZoneScope::ZoneScope(Zone* zone)
: zone_(zone) {
zone_->scope_nesting_++;
}
bool ZoneScope::ShouldDeleteOnExit() {
return zone_->scope_nesting_ == 1;
}
} } // namespace v8::internal } } // namespace v8::internal
#endif // V8_ZONE_INL_H_ #endif // V8_ZONE_INL_H_
...@@ -73,15 +73,37 @@ Zone::Zone(Isolate* isolate) ...@@ -73,15 +73,37 @@ Zone::Zone(Isolate* isolate)
segment_bytes_allocated_(0), segment_bytes_allocated_(0),
position_(0), position_(0),
limit_(0), limit_(0),
scope_nesting_(0),
segment_head_(NULL), segment_head_(NULL),
isolate_(isolate) { isolate_(isolate) {
} }
ZoneScope::~ZoneScope() { Zone::~Zone() {
if (ShouldDeleteOnExit()) zone_->DeleteAll(); #ifdef DEBUG
zone_->scope_nesting_--; // Constant byte value used for zapping dead memory in debug mode.
static const unsigned char kZapDeadByte = 0xcd;
#endif
// Traverse the chained list of segments, zapping
// (in debug mode) and freeing every segment
Segment* current = segment_head_;
while (current != NULL) {
Segment* next = current->next();
int size = current->size();
#ifdef DEBUG
// Zap the entire current segment (including the header).
memset(current, kZapDeadByte, size);
#endif
DeleteSegment(current, size);
current = next;
}
// We must clear the position and limit to force
// a new segment to be allocated on demand.
position_ = limit_ = 0;
// Update the head segment.
segment_head_ = NULL;
} }
...@@ -105,66 +127,6 @@ void Zone::DeleteSegment(Segment* segment, int size) { ...@@ -105,66 +127,6 @@ void Zone::DeleteSegment(Segment* segment, int size) {
} }
void Zone::DeleteAll() {
#ifdef DEBUG
// Constant byte value used for zapping dead memory in debug mode.
static const unsigned char kZapDeadByte = 0xcd;
#endif
// Find a segment with a suitable size to keep around.
Segment* keep = segment_head_;
while (keep != NULL && keep->size() > kMaximumKeptSegmentSize) {
keep = keep->next();
}
// Traverse the chained list of segments, zapping (in debug mode)
// and freeing every segment except the one we wish to keep.
Segment* current = segment_head_;
while (current != NULL) {
Segment* next = current->next();
if (current == keep) {
// Unlink the segment we wish to keep from the list.
current->clear_next();
} else {
int size = current->size();
#ifdef DEBUG
// Zap the entire current segment (including the header).
memset(current, kZapDeadByte, size);
#endif
DeleteSegment(current, size);
}
current = next;
}
// If we have found a segment we want to keep, we must recompute the
// variables 'position' and 'limit' to prepare for future allocate
// attempts. Otherwise, we must clear the position and limit to
// force a new segment to be allocated on demand.
if (keep != NULL) {
Address start = keep->start();
position_ = RoundUp(start, kAlignment);
limit_ = keep->end();
#ifdef DEBUG
// Zap the contents of the kept segment (but not the header).
memset(start, kZapDeadByte, keep->capacity());
#endif
} else {
position_ = limit_ = 0;
}
// Update the head segment to be the kept segment (if any).
segment_head_ = keep;
}
void Zone::DeleteKeptSegment() {
if (segment_head_ != NULL) {
DeleteSegment(segment_head_, segment_head_->size());
segment_head_ = NULL;
}
}
Address Zone::NewExpand(int size) { Address Zone::NewExpand(int size) {
// Make sure the requested size is already properly aligned and that // Make sure the requested size is already properly aligned and that
// there isn't enough room in the Zone to satisfy the request. // there isn't enough room in the Zone to satisfy the request.
......
...@@ -58,7 +58,7 @@ class Isolate; ...@@ -58,7 +58,7 @@ class Isolate;
class Zone { class Zone {
public: public:
explicit Zone(Isolate* isolate); explicit Zone(Isolate* isolate);
~Zone() { DeleteKeptSegment(); } ~Zone();
// Allocate 'size' bytes of memory in the Zone; expands the Zone by // Allocate 'size' bytes of memory in the Zone; expands the Zone by
// allocating new segments of memory on demand using malloc(). // allocating new segments of memory on demand using malloc().
inline void* New(int size); inline void* New(int size);
...@@ -66,13 +66,6 @@ class Zone { ...@@ -66,13 +66,6 @@ class Zone {
template <typename T> template <typename T>
inline T* NewArray(int length); inline T* NewArray(int length);
// Deletes all objects and free all memory allocated in the Zone. Keeps one
// small (size <= kMaximumKeptSegmentSize) segment around if it finds one.
void DeleteAll();
// Deletes the last small segment kept around by DeleteAll().
void DeleteKeptSegment();
// Returns true if more memory has been allocated in zones than // Returns true if more memory has been allocated in zones than
// the limit allows. // the limit allows.
inline bool excess_allocation(); inline bool excess_allocation();
...@@ -85,7 +78,6 @@ class Zone { ...@@ -85,7 +78,6 @@ class Zone {
private: private:
friend class Isolate; friend class Isolate;
friend class ZoneScope;
// All pointers returned from New() have this alignment. In addition, if the // All pointers returned from New() have this alignment. In addition, if the
// object being allocated has a size that is divisible by 8 then its alignment // object being allocated has a size that is divisible by 8 then its alignment
...@@ -98,9 +90,6 @@ class Zone { ...@@ -98,9 +90,6 @@ class Zone {
// Never allocate segments larger than this size in bytes. // Never allocate segments larger than this size in bytes.
static const int kMaximumSegmentSize = 1 * MB; static const int kMaximumSegmentSize = 1 * MB;
// Never keep segments larger than this size in bytes around.
static const int kMaximumKeptSegmentSize = 64 * KB;
// Report zone excess when allocation exceeds this limit. // Report zone excess when allocation exceeds this limit.
int zone_excess_limit_; int zone_excess_limit_;
...@@ -131,8 +120,6 @@ class Zone { ...@@ -131,8 +120,6 @@ class Zone {
Address position_; Address position_;
Address limit_; Address limit_;
int scope_nesting_;
Segment* segment_head_; Segment* segment_head_;
Isolate* isolate_; Isolate* isolate_;
}; };
...@@ -225,26 +212,6 @@ class ZoneList: public List<T, ZoneAllocationPolicy> { ...@@ -225,26 +212,6 @@ class ZoneList: public List<T, ZoneAllocationPolicy> {
}; };
// ZoneScopes keep track of the current parsing and compilation
// nesting and cleans up generated ASTs in the Zone when exiting the
// outer-most scope.
class ZoneScope BASE_EMBEDDED {
public:
INLINE(ZoneScope(Zone* zone));
virtual ~ZoneScope();
Zone* zone() const { return zone_; }
inline bool ShouldDeleteOnExit();
inline static int nesting();
private:
Zone* zone_;
};
// A zone splay tree. The config type parameter encapsulates the // A zone splay tree. The config type parameter encapsulates the
// different configurations of a concrete splay tree (see splay-tree.h). // different configurations of a concrete splay tree (see splay-tree.h).
// The tree itself and all its elements are allocated in the Zone. // The tree itself and all its elements are allocated in the Zone.
......
...@@ -40,9 +40,8 @@ TEST(List) { ...@@ -40,9 +40,8 @@ TEST(List) {
CHECK_EQ(0, list->length()); CHECK_EQ(0, list->length());
Isolate* isolate = Isolate::Current(); Isolate* isolate = Isolate::Current();
Zone* zone = isolate->runtime_zone(); Zone zone(isolate);
ZoneScope zone_scope(zone); AstNodeFactory<AstNullVisitor> factory(isolate, &zone);
AstNodeFactory<AstNullVisitor> factory(isolate, zone);
AstNode* node = factory.NewEmptyStatement(); AstNode* node = factory.NewEmptyStatement();
list->Add(node); list->Add(node);
CHECK_EQ(1, list->length()); CHECK_EQ(1, list->length());
......
...@@ -36,17 +36,16 @@ using namespace v8::internal; ...@@ -36,17 +36,16 @@ using namespace v8::internal;
TEST(BitVector) { TEST(BitVector) {
v8::internal::V8::Initialize(NULL); v8::internal::V8::Initialize(NULL);
Zone* zone = Isolate::Current()->runtime_zone(); Zone zone(Isolate::Current());
ZoneScope zone_scope(zone);
{ {
BitVector v(15, zone); BitVector v(15, &zone);
v.Add(1); v.Add(1);
CHECK(v.Contains(1)); CHECK(v.Contains(1));
v.Remove(0); v.Remove(0);
CHECK(!v.Contains(0)); CHECK(!v.Contains(0));
v.Add(0); v.Add(0);
v.Add(1); v.Add(1);
BitVector w(15, zone); BitVector w(15, &zone);
w.Add(1); w.Add(1);
v.Intersect(w); v.Intersect(w);
CHECK(!v.Contains(0)); CHECK(!v.Contains(0));
...@@ -54,7 +53,7 @@ TEST(BitVector) { ...@@ -54,7 +53,7 @@ TEST(BitVector) {
} }
{ {
BitVector v(64, zone); BitVector v(64, &zone);
v.Add(27); v.Add(27);
v.Add(30); v.Add(30);
v.Add(31); v.Add(31);
...@@ -72,9 +71,9 @@ TEST(BitVector) { ...@@ -72,9 +71,9 @@ TEST(BitVector) {
} }
{ {
BitVector v(15, zone); BitVector v(15, &zone);
v.Add(0); v.Add(0);
BitVector w(15, zone); BitVector w(15, &zone);
w.Add(1); w.Add(1);
v.Union(w); v.Union(w);
CHECK(v.Contains(0)); CHECK(v.Contains(0));
...@@ -82,13 +81,13 @@ TEST(BitVector) { ...@@ -82,13 +81,13 @@ TEST(BitVector) {
} }
{ {
BitVector v(15, zone); BitVector v(15, &zone);
v.Add(0); v.Add(0);
BitVector w(15, zone); BitVector w(15, &zone);
w = v; w = v;
CHECK(w.Contains(0)); CHECK(w.Contains(0));
w.Add(1); w.Add(1);
BitVector u(w, zone); BitVector u(w, &zone);
CHECK(u.Contains(0)); CHECK(u.Contains(0));
CHECK(u.Contains(1)); CHECK(u.Contains(1));
v.Union(w); v.Union(w);
...@@ -97,9 +96,9 @@ TEST(BitVector) { ...@@ -97,9 +96,9 @@ TEST(BitVector) {
} }
{ {
BitVector v(35, zone); BitVector v(35, &zone);
v.Add(0); v.Add(0);
BitVector w(35, zone); BitVector w(35, &zone);
w.Add(33); w.Add(33);
v.Union(w); v.Union(w);
CHECK(v.Contains(0)); CHECK(v.Contains(0));
...@@ -107,15 +106,15 @@ TEST(BitVector) { ...@@ -107,15 +106,15 @@ TEST(BitVector) {
} }
{ {
BitVector v(35, zone); BitVector v(35, &zone);
v.Add(32); v.Add(32);
v.Add(33); v.Add(33);
BitVector w(35, zone); BitVector w(35, &zone);
w.Add(33); w.Add(33);
v.Intersect(w); v.Intersect(w);
CHECK(!v.Contains(32)); CHECK(!v.Contains(32));
CHECK(v.Contains(33)); CHECK(v.Contains(33));
BitVector r(35, zone); BitVector r(35, &zone);
r.CopyFrom(v); r.CopyFrom(v);
CHECK(!r.Contains(32)); CHECK(!r.Contains(32));
CHECK(r.Contains(33)); CHECK(r.Contains(33));
......
...@@ -76,19 +76,20 @@ class DiffChunkStruct : public ZoneObject { ...@@ -76,19 +76,20 @@ class DiffChunkStruct : public ZoneObject {
class ListDiffOutputWriter : public Comparator::Output { class ListDiffOutputWriter : public Comparator::Output {
public: public:
explicit ListDiffOutputWriter(DiffChunkStruct** next_chunk_pointer) explicit ListDiffOutputWriter(DiffChunkStruct** next_chunk_pointer,
: next_chunk_pointer_(next_chunk_pointer) { Zone* zone)
: next_chunk_pointer_(next_chunk_pointer), zone_(zone) {
(*next_chunk_pointer_) = NULL; (*next_chunk_pointer_) = NULL;
} }
void AddChunk(int pos1, int pos2, int len1, int len2) { void AddChunk(int pos1, int pos2, int len1, int len2) {
current_chunk_ = new(Isolate::Current()->runtime_zone()) DiffChunkStruct( current_chunk_ = new(zone_) DiffChunkStruct(pos1, pos2, len1, len2);
pos1, pos2, len1, len2);
(*next_chunk_pointer_) = current_chunk_; (*next_chunk_pointer_) = current_chunk_;
next_chunk_pointer_ = &current_chunk_->next; next_chunk_pointer_ = &current_chunk_->next;
} }
private: private:
DiffChunkStruct** next_chunk_pointer_; DiffChunkStruct** next_chunk_pointer_;
DiffChunkStruct* current_chunk_; DiffChunkStruct* current_chunk_;
Zone* zone_;
}; };
...@@ -96,10 +97,10 @@ void CompareStringsOneWay(const char* s1, const char* s2, ...@@ -96,10 +97,10 @@ void CompareStringsOneWay(const char* s1, const char* s2,
int expected_diff_parameter = -1) { int expected_diff_parameter = -1) {
StringCompareInput input(s1, s2); StringCompareInput input(s1, s2);
ZoneScope zone_scope(Isolate::Current()->runtime_zone()); Zone zone(Isolate::Current());
DiffChunkStruct* first_chunk; DiffChunkStruct* first_chunk;
ListDiffOutputWriter writer(&first_chunk); ListDiffOutputWriter writer(&first_chunk, &zone);
Comparator::CalculateDifference(&input, &writer); Comparator::CalculateDifference(&input, &writer);
......
This diff is collapsed.
...@@ -133,12 +133,12 @@ class AsciiResource: public v8::String::ExternalAsciiStringResource, ...@@ -133,12 +133,12 @@ class AsciiResource: public v8::String::ExternalAsciiStringResource,
static void InitializeBuildingBlocks(Handle<String>* building_blocks, static void InitializeBuildingBlocks(Handle<String>* building_blocks,
int bb_length, int bb_length,
bool long_blocks, bool long_blocks,
RandomNumberGenerator* rng) { RandomNumberGenerator* rng,
Zone* zone) {
// A list of pointers that we don't have any interest in cleaning up. // A list of pointers that we don't have any interest in cleaning up.
// If they are reachable from a root then leak detection won't complain. // If they are reachable from a root then leak detection won't complain.
Isolate* isolate = Isolate::Current(); Isolate* isolate = Isolate::Current();
Factory* factory = isolate->factory(); Factory* factory = isolate->factory();
Zone* zone = isolate->runtime_zone();
for (int i = 0; i < bb_length; i++) { for (int i = 0; i < bb_length; i++) {
int len = rng->next(16); int len = rng->next(16);
int slice_head_chars = 0; int slice_head_chars = 0;
...@@ -263,7 +263,7 @@ void ConsStringStats::VerifyEqual(const ConsStringStats& that) const { ...@@ -263,7 +263,7 @@ void ConsStringStats::VerifyEqual(const ConsStringStats& that) const {
class ConsStringGenerationData { class ConsStringGenerationData {
public: public:
static const int kNumberOfBuildingBlocks = 256; static const int kNumberOfBuildingBlocks = 256;
explicit ConsStringGenerationData(bool long_blocks); ConsStringGenerationData(bool long_blocks, Zone* zone);
void Reset(); void Reset();
inline Handle<String> block(int offset); inline Handle<String> block(int offset);
inline Handle<String> block(uint32_t offset); inline Handle<String> block(uint32_t offset);
...@@ -285,10 +285,11 @@ class ConsStringGenerationData { ...@@ -285,10 +285,11 @@ class ConsStringGenerationData {
}; };
ConsStringGenerationData::ConsStringGenerationData(bool long_blocks) { ConsStringGenerationData::ConsStringGenerationData(bool long_blocks,
Zone* zone) {
rng_.init(); rng_.init();
InitializeBuildingBlocks( InitializeBuildingBlocks(
building_blocks_, kNumberOfBuildingBlocks, long_blocks, &rng_); building_blocks_, kNumberOfBuildingBlocks, long_blocks, &rng_, zone);
empty_string_ = Isolate::Current()->heap()->empty_string(); empty_string_ = Isolate::Current()->heap()->empty_string();
Reset(); Reset();
} }
...@@ -570,8 +571,8 @@ TEST(Traverse) { ...@@ -570,8 +571,8 @@ TEST(Traverse) {
printf("TestTraverse\n"); printf("TestTraverse\n");
CcTest::InitializeVM(); CcTest::InitializeVM();
v8::HandleScope scope(CcTest::isolate()); v8::HandleScope scope(CcTest::isolate());
ZoneScope zone(Isolate::Current()->runtime_zone()); Zone zone(Isolate::Current());
ConsStringGenerationData data(false); ConsStringGenerationData data(false, &zone);
Handle<String> flat = ConstructBalanced(&data); Handle<String> flat = ConstructBalanced(&data);
FlattenString(flat); FlattenString(flat);
Handle<String> left_asymmetric = ConstructLeft(&data, DEEP_DEPTH); Handle<String> left_asymmetric = ConstructLeft(&data, DEEP_DEPTH);
...@@ -660,8 +661,8 @@ void TestStringCharacterStream(BuildString build, int test_cases) { ...@@ -660,8 +661,8 @@ void TestStringCharacterStream(BuildString build, int test_cases) {
CcTest::InitializeVM(); CcTest::InitializeVM();
Isolate* isolate = Isolate::Current(); Isolate* isolate = Isolate::Current();
HandleScope outer_scope(isolate); HandleScope outer_scope(isolate);
ZoneScope zone(Isolate::Current()->runtime_zone()); Zone zone(isolate);
ConsStringGenerationData data(true); ConsStringGenerationData data(true, &zone);
for (int i = 0; i < test_cases; i++) { for (int i = 0; i < test_cases; i++) {
printf("%d\n", i); printf("%d\n", i);
HandleScope inner_scope(isolate); HandleScope inner_scope(isolate);
...@@ -929,11 +930,11 @@ TEST(Utf8Conversion) { ...@@ -929,11 +930,11 @@ TEST(Utf8Conversion) {
TEST(ExternalShortStringAdd) { TEST(ExternalShortStringAdd) {
ZoneScope zonescope(Isolate::Current()->runtime_zone()); Isolate* isolate = Isolate::Current();
Zone zone(isolate);
CcTest::InitializeVM(); CcTest::InitializeVM();
v8::HandleScope handle_scope(CcTest::isolate()); v8::HandleScope handle_scope(CcTest::isolate());
Zone* zone = Isolate::Current()->runtime_zone();
// Make sure we cover all always-flat lengths and at least one above. // Make sure we cover all always-flat lengths and at least one above.
static const int kMaxLength = 20; static const int kMaxLength = 20;
...@@ -947,25 +948,25 @@ TEST(ExternalShortStringAdd) { ...@@ -947,25 +948,25 @@ TEST(ExternalShortStringAdd) {
// Generate short ascii and non-ascii external strings. // Generate short ascii and non-ascii external strings.
for (int i = 0; i <= kMaxLength; i++) { for (int i = 0; i <= kMaxLength; i++) {
char* ascii = zone->NewArray<char>(i + 1); char* ascii = zone.NewArray<char>(i + 1);
for (int j = 0; j < i; j++) { for (int j = 0; j < i; j++) {
ascii[j] = 'a'; ascii[j] = 'a';
} }
// Terminating '\0' is left out on purpose. It is not required for external // Terminating '\0' is left out on purpose. It is not required for external
// string data. // string data.
AsciiResource* ascii_resource = AsciiResource* ascii_resource =
new(zone) AsciiResource(Vector<const char>(ascii, i)); new(&zone) AsciiResource(Vector<const char>(ascii, i));
v8::Local<v8::String> ascii_external_string = v8::Local<v8::String> ascii_external_string =
v8::String::NewExternal(ascii_resource); v8::String::NewExternal(ascii_resource);
ascii_external_strings->Set(v8::Integer::New(i), ascii_external_string); ascii_external_strings->Set(v8::Integer::New(i), ascii_external_string);
uc16* non_ascii = zone->NewArray<uc16>(i + 1); uc16* non_ascii = zone.NewArray<uc16>(i + 1);
for (int j = 0; j < i; j++) { for (int j = 0; j < i; j++) {
non_ascii[j] = 0x1234; non_ascii[j] = 0x1234;
} }
// Terminating '\0' is left out on purpose. It is not required for external // Terminating '\0' is left out on purpose. It is not required for external
// string data. // string data.
Resource* resource = new(zone) Resource(Vector<const uc16>(non_ascii, i)); Resource* resource = new(&zone) Resource(Vector<const uc16>(non_ascii, i));
v8::Local<v8::String> non_ascii_external_string = v8::Local<v8::String> non_ascii_external_string =
v8::String::NewExternal(resource); v8::String::NewExternal(resource);
non_ascii_external_strings->Set(v8::Integer::New(i), non_ascii_external_strings->Set(v8::Integer::New(i),
...@@ -1021,7 +1022,7 @@ TEST(CachedHashOverflow) { ...@@ -1021,7 +1022,7 @@ TEST(CachedHashOverflow) {
// values didn't fit in the hash field. // values didn't fit in the hash field.
// See http://code.google.com/p/v8/issues/detail?id=728 // See http://code.google.com/p/v8/issues/detail?id=728
Isolate* isolate = Isolate::Current(); Isolate* isolate = Isolate::Current();
ZoneScope zone(isolate->runtime_zone()); Zone zone(isolate);
CcTest::InitializeVM(); CcTest::InitializeVM();
v8::HandleScope handle_scope(CcTest::isolate()); v8::HandleScope handle_scope(CcTest::isolate());
......
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