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

Side by Side Diff: src/bootstrapper.cc

Issue 360050: Keep natives source code in external strings instead of putting... (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: '' Created 11 years, 1 month 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/objects.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 18 matching lines...) Expand all
29 29
30 #include "accessors.h" 30 #include "accessors.h"
31 #include "api.h" 31 #include "api.h"
32 #include "bootstrapper.h" 32 #include "bootstrapper.h"
33 #include "compiler.h" 33 #include "compiler.h"
34 #include "debug.h" 34 #include "debug.h"
35 #include "execution.h" 35 #include "execution.h"
36 #include "global-handles.h" 36 #include "global-handles.h"
37 #include "macro-assembler.h" 37 #include "macro-assembler.h"
38 #include "natives.h" 38 #include "natives.h"
39 #include "snapshot.h"
39 40
40 namespace v8 { 41 namespace v8 {
41 namespace internal { 42 namespace internal {
42 43
43 // A SourceCodeCache uses a FixedArray to store pairs of 44 // A SourceCodeCache uses a FixedArray to store pairs of
44 // (AsciiString*, JSFunction*), mapping names of native code files 45 // (AsciiString*, JSFunction*), mapping names of native code files
45 // (runtime.js, etc.) to precompiled functions. Instead of mapping 46 // (runtime.js, etc.) to precompiled functions. Instead of mapping
46 // names to functions it might make sense to let the JS2C tool 47 // names to functions it might make sense to let the JS2C tool
47 // generate an index for each native JS file. 48 // generate an index for each native JS file.
48 class SourceCodeCache BASE_EMBEDDED { 49 class SourceCodeCache BASE_EMBEDDED {
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
85 } 86 }
86 87
87 private: 88 private:
88 Script::Type type_; 89 Script::Type type_;
89 FixedArray* cache_; 90 FixedArray* cache_;
90 DISALLOW_COPY_AND_ASSIGN(SourceCodeCache); 91 DISALLOW_COPY_AND_ASSIGN(SourceCodeCache);
91 }; 92 };
92 93
93 static SourceCodeCache natives_cache(Script::TYPE_NATIVE); 94 static SourceCodeCache natives_cache(Script::TYPE_NATIVE);
94 static SourceCodeCache extensions_cache(Script::TYPE_EXTENSION); 95 static SourceCodeCache extensions_cache(Script::TYPE_EXTENSION);
96 // This is for delete, not delete[].
97 static List<char*>* delete_these_non_arrays_on_tear_down = NULL;
95 98
96 99
97 Handle<String> Bootstrapper::NativesSourceLookup(int index) { 100 Handle<String> Bootstrapper::NativesSourceLookup(int index) {
98 ASSERT(0 <= index && index < Natives::GetBuiltinsCount()); 101 ASSERT(0 <= index && index < Natives::GetBuiltinsCount());
99 if (Heap::natives_source_cache()->get(index)->IsUndefined()) { 102 if (Heap::natives_source_cache()->get(index)->IsUndefined()) {
100 Handle<String> source_code = 103 if (!Snapshot::IsEnabled || FLAG_new_snapshot) {
101 Factory::NewStringFromAscii(Natives::GetScriptSource(index)); 104 if (delete_these_non_arrays_on_tear_down == NULL) {
102 Heap::natives_source_cache()->set(index, *source_code); 105 delete_these_non_arrays_on_tear_down = new List<char*>(2);
106 }
107 // We can use external strings for the natives.
108 NativesExternalStringResource* resource =
109 new NativesExternalStringResource(
110 Natives::GetScriptSource(index).start());
111 // The resources are small objects and we only make a fixed number of
112 // them, but lets clean them up on exit for neatness.
113 delete_these_non_arrays_on_tear_down->
114 Add(reinterpret_cast<char*>(resource));
115 Handle<String> source_code =
116 Factory::NewExternalStringFromAscii(resource);
117 Heap::natives_source_cache()->set(index, *source_code);
118 } else {
119 // Old snapshot code can't cope with external strings at all.
120 Handle<String> source_code =
121 Factory::NewStringFromAscii(Natives::GetScriptSource(index));
122 Heap::natives_source_cache()->set(index, *source_code);
123 }
103 } 124 }
104 Handle<Object> cached_source(Heap::natives_source_cache()->get(index)); 125 Handle<Object> cached_source(Heap::natives_source_cache()->get(index));
105 return Handle<String>::cast(cached_source); 126 return Handle<String>::cast(cached_source);
106 } 127 }
107 128
108 129
109 bool Bootstrapper::NativesCacheLookup(Vector<const char> name, 130 bool Bootstrapper::NativesCacheLookup(Vector<const char> name,
110 Handle<JSFunction>* handle) { 131 Handle<JSFunction>* handle) {
111 return natives_cache.Lookup(name, handle); 132 return natives_cache.Lookup(name, handle);
112 } 133 }
113 134
114 135
115 void Bootstrapper::NativesCacheAdd(Vector<const char> name, 136 void Bootstrapper::NativesCacheAdd(Vector<const char> name,
116 Handle<JSFunction> fun) { 137 Handle<JSFunction> fun) {
117 natives_cache.Add(name, fun); 138 natives_cache.Add(name, fun);
118 } 139 }
119 140
120 141
121 void Bootstrapper::Initialize(bool create_heap_objects) { 142 void Bootstrapper::Initialize(bool create_heap_objects) {
122 natives_cache.Initialize(create_heap_objects); 143 natives_cache.Initialize(create_heap_objects);
123 extensions_cache.Initialize(create_heap_objects); 144 extensions_cache.Initialize(create_heap_objects);
124 } 145 }
125 146
126 147
127 void Bootstrapper::TearDown() { 148 void Bootstrapper::TearDown() {
149 if (delete_these_non_arrays_on_tear_down != NULL) {
150 int len = delete_these_non_arrays_on_tear_down->length();
151 ASSERT(len < 20); // Don't use this mechanism for unbounded allocations.
152 for (int i = 0; i < len; i++) {
153 delete delete_these_non_arrays_on_tear_down->at(i);
154 }
155 delete delete_these_non_arrays_on_tear_down;
156 delete_these_non_arrays_on_tear_down = NULL;
157 }
158
128 natives_cache.Initialize(false); // Yes, symmetrical 159 natives_cache.Initialize(false); // Yes, symmetrical
129 extensions_cache.Initialize(false); 160 extensions_cache.Initialize(false);
130 } 161 }
131 162
132 163
133 // Pending fixups are code positions that refer to builtin code 164 // Pending fixups are code positions that refer to builtin code
134 // objects that were not available at the time the code was generated. 165 // objects that were not available at the time the code was generated.
135 // The pending list is processed whenever an environment has been 166 // The pending list is processed whenever an environment has been
136 // created. 167 // created.
137 class PendingFixups : public AllStatic { 168 class PendingFixups : public AllStatic {
(...skipping 1464 matching lines...) Expand 10 before | Expand all | Expand 10 after
1602 } 1633 }
1603 1634
1604 1635
1605 // Restore statics that are thread local. 1636 // Restore statics that are thread local.
1606 char* Genesis::RestoreState(char* from) { 1637 char* Genesis::RestoreState(char* from) {
1607 current_ = *reinterpret_cast<Genesis**>(from); 1638 current_ = *reinterpret_cast<Genesis**>(from);
1608 return from + sizeof(current_); 1639 return from + sizeof(current_);
1609 } 1640 }
1610 1641
1611 } } // namespace v8::internal 1642 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/bootstrapper.h ('k') | src/objects.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698