Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(69)

Side by Side Diff: src/bootstrapper.cc

Issue 669240: - Remove function boilerplate objects and use SharedFunctionInfos in... (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: Committed Created 10 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/bootstrapper.h ('k') | src/codegen.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2006-2008 the V8 project authors. All rights reserved. 1 // Copyright 2006-2008 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 52
53 void Initialize(bool create_heap_objects) { 53 void Initialize(bool create_heap_objects) {
54 cache_ = create_heap_objects ? Heap::empty_fixed_array() : NULL; 54 cache_ = create_heap_objects ? Heap::empty_fixed_array() : NULL;
55 } 55 }
56 56
57 void Iterate(ObjectVisitor* v) { 57 void Iterate(ObjectVisitor* v) {
58 v->VisitPointer(BitCast<Object**, FixedArray**>(&cache_)); 58 v->VisitPointer(BitCast<Object**, FixedArray**>(&cache_));
59 } 59 }
60 60
61 61
62 bool Lookup(Vector<const char> name, Handle<JSFunction>* handle) { 62 bool Lookup(Vector<const char> name, Handle<SharedFunctionInfo>* handle) {
63 for (int i = 0; i < cache_->length(); i+=2) { 63 for (int i = 0; i < cache_->length(); i+=2) {
64 SeqAsciiString* str = SeqAsciiString::cast(cache_->get(i)); 64 SeqAsciiString* str = SeqAsciiString::cast(cache_->get(i));
65 if (str->IsEqualTo(name)) { 65 if (str->IsEqualTo(name)) {
66 *handle = Handle<JSFunction>(JSFunction::cast(cache_->get(i + 1))); 66 *handle = Handle<SharedFunctionInfo>(
67 SharedFunctionInfo::cast(cache_->get(i + 1)));
67 return true; 68 return true;
68 } 69 }
69 } 70 }
70 return false; 71 return false;
71 } 72 }
72 73
73 74
74 void Add(Vector<const char> name, Handle<JSFunction> fun) { 75 void Add(Vector<const char> name, Handle<SharedFunctionInfo> shared) {
75 ASSERT(fun->IsBoilerplate());
76 HandleScope scope; 76 HandleScope scope;
77 int length = cache_->length(); 77 int length = cache_->length();
78 Handle<FixedArray> new_array = 78 Handle<FixedArray> new_array =
79 Factory::NewFixedArray(length + 2, TENURED); 79 Factory::NewFixedArray(length + 2, TENURED);
80 cache_->CopyTo(0, *new_array, 0, cache_->length()); 80 cache_->CopyTo(0, *new_array, 0, cache_->length());
81 cache_ = *new_array; 81 cache_ = *new_array;
82 Handle<String> str = Factory::NewStringFromAscii(name, TENURED); 82 Handle<String> str = Factory::NewStringFromAscii(name, TENURED);
83 cache_->set(length, *str); 83 cache_->set(length, *str);
84 cache_->set(length + 1, *fun); 84 cache_->set(length + 1, *shared);
85 Script::cast(fun->shared()->script())->set_type(Smi::FromInt(type_)); 85 Script::cast(shared->script())->set_type(Smi::FromInt(type_));
86 } 86 }
87 87
88 private: 88 private:
89 Script::Type type_; 89 Script::Type type_;
90 FixedArray* cache_; 90 FixedArray* cache_;
91 DISALLOW_COPY_AND_ASSIGN(SourceCodeCache); 91 DISALLOW_COPY_AND_ASSIGN(SourceCodeCache);
92 }; 92 };
93 93
94 static SourceCodeCache natives_cache(Script::TYPE_NATIVE); 94 static SourceCodeCache natives_cache(Script::TYPE_NATIVE);
95 static SourceCodeCache extensions_cache(Script::TYPE_EXTENSION); 95 static SourceCodeCache extensions_cache(Script::TYPE_EXTENSION);
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
128 Factory::NewStringFromAscii(Natives::GetScriptSource(index)); 128 Factory::NewStringFromAscii(Natives::GetScriptSource(index));
129 Heap::natives_source_cache()->set(index, *source_code); 129 Heap::natives_source_cache()->set(index, *source_code);
130 } 130 }
131 } 131 }
132 Handle<Object> cached_source(Heap::natives_source_cache()->get(index)); 132 Handle<Object> cached_source(Heap::natives_source_cache()->get(index));
133 return Handle<String>::cast(cached_source); 133 return Handle<String>::cast(cached_source);
134 } 134 }
135 135
136 136
137 bool Bootstrapper::NativesCacheLookup(Vector<const char> name, 137 bool Bootstrapper::NativesCacheLookup(Vector<const char> name,
138 Handle<JSFunction>* handle) { 138 Handle<SharedFunctionInfo>* handle) {
139 return natives_cache.Lookup(name, handle); 139 return natives_cache.Lookup(name, handle);
140 } 140 }
141 141
142 142
143 void Bootstrapper::NativesCacheAdd(Vector<const char> name, 143 void Bootstrapper::NativesCacheAdd(Vector<const char> name,
144 Handle<JSFunction> fun) { 144 Handle<SharedFunctionInfo> fun) {
145 natives_cache.Add(name, fun); 145 natives_cache.Add(name, fun);
146 } 146 }
147 147
148 148
149 void Bootstrapper::Initialize(bool create_heap_objects) { 149 void Bootstrapper::Initialize(bool create_heap_objects) {
150 natives_cache.Initialize(create_heap_objects); 150 natives_cache.Initialize(create_heap_objects);
151 extensions_cache.Initialize(create_heap_objects); 151 extensions_cache.Initialize(create_heap_objects);
152 } 152 }
153 153
154 154
(...skipping 646 matching lines...) Expand 10 before | Expand all | Expand 10 after
801 return result; 801 return result;
802 } 802 }
803 803
804 804
805 bool Genesis::CompileScriptCached(Vector<const char> name, 805 bool Genesis::CompileScriptCached(Vector<const char> name,
806 Handle<String> source, 806 Handle<String> source,
807 SourceCodeCache* cache, 807 SourceCodeCache* cache,
808 v8::Extension* extension, 808 v8::Extension* extension,
809 bool use_runtime_context) { 809 bool use_runtime_context) {
810 HandleScope scope; 810 HandleScope scope;
811 Handle<JSFunction> boilerplate; 811 Handle<SharedFunctionInfo> function_info;
812 812
813 // If we can't find the function in the cache, we compile a new 813 // If we can't find the function in the cache, we compile a new
814 // function and insert it into the cache. 814 // function and insert it into the cache.
815 if (!cache->Lookup(name, &boilerplate)) { 815 if (!cache->Lookup(name, &function_info)) {
816 ASSERT(source->IsAsciiRepresentation()); 816 ASSERT(source->IsAsciiRepresentation());
817 Handle<String> script_name = Factory::NewStringFromUtf8(name); 817 Handle<String> script_name = Factory::NewStringFromUtf8(name);
818 boilerplate = 818 function_info = Compiler::Compile(
819 Compiler::Compile( 819 source,
820 source, 820 script_name,
821 script_name, 821 0,
822 0, 822 0,
823 0, 823 extension,
824 extension, 824 NULL,
825 NULL, 825 Handle<String>::null(),
826 Handle<String>::null(), 826 use_runtime_context ? NATIVES_CODE : NOT_NATIVES_CODE);
827 use_runtime_context ? NATIVES_CODE : NOT_NATIVES_CODE); 827 if (function_info.is_null()) return false;
828 if (boilerplate.is_null()) return false; 828 cache->Add(name, function_info);
829 cache->Add(name, boilerplate);
830 } 829 }
831 830
832 // Setup the function context. Conceptually, we should clone the 831 // Setup the function context. Conceptually, we should clone the
833 // function before overwriting the context but since we're in a 832 // function before overwriting the context but since we're in a
834 // single-threaded environment it is not strictly necessary. 833 // single-threaded environment it is not strictly necessary.
835 ASSERT(Top::context()->IsGlobalContext()); 834 ASSERT(Top::context()->IsGlobalContext());
836 Handle<Context> context = 835 Handle<Context> context =
837 Handle<Context>(use_runtime_context 836 Handle<Context>(use_runtime_context
838 ? Top::context()->runtime_context() 837 ? Top::context()->runtime_context()
839 : Top::context()); 838 : Top::context());
840 Handle<JSFunction> fun = 839 Handle<JSFunction> fun =
841 Factory::NewFunctionFromBoilerplate(boilerplate, context); 840 Factory::NewFunctionFromSharedFunctionInfo(function_info, context);
842 841
843 // Call function using either the runtime object or the global 842 // Call function using either the runtime object or the global
844 // object as the receiver. Provide no parameters. 843 // object as the receiver. Provide no parameters.
845 Handle<Object> receiver = 844 Handle<Object> receiver =
846 Handle<Object>(use_runtime_context 845 Handle<Object>(use_runtime_context
847 ? Top::context()->builtins() 846 ? Top::context()->builtins()
848 : Top::context()->global()); 847 : Top::context()->global());
849 bool has_pending_exception; 848 bool has_pending_exception;
850 Handle<Object> result = 849 Handle<Object> result =
851 Execution::Call(fun, receiver, 0, NULL, &has_pending_exception); 850 Execution::Call(fun, receiver, 0, NULL, &has_pending_exception);
(...skipping 678 matching lines...) Expand 10 before | Expand all | Expand 10 after
1530 } 1529 }
1531 1530
1532 1531
1533 // Restore statics that are thread local. 1532 // Restore statics that are thread local.
1534 char* Genesis::RestoreState(char* from) { 1533 char* Genesis::RestoreState(char* from) {
1535 current_ = *reinterpret_cast<Genesis**>(from); 1534 current_ = *reinterpret_cast<Genesis**>(from);
1536 return from + sizeof(current_); 1535 return from + sizeof(current_);
1537 } 1536 }
1538 1537
1539 } } // namespace v8::internal 1538 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/bootstrapper.h ('k') | src/codegen.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698