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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/bootstrapper.h ('k') | src/objects.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/bootstrapper.cc
===================================================================
--- src/bootstrapper.cc (revision 3220)
+++ src/bootstrapper.cc (working copy)
@@ -36,6 +36,7 @@
#include "global-handles.h"
#include "macro-assembler.h"
#include "natives.h"
+#include "snapshot.h"
namespace v8 {
namespace internal {
@@ -92,14 +93,34 @@
static SourceCodeCache natives_cache(Script::TYPE_NATIVE);
static SourceCodeCache extensions_cache(Script::TYPE_EXTENSION);
+// This is for delete, not delete[].
+static List<char*>* delete_these_non_arrays_on_tear_down = NULL;
Handle<String> Bootstrapper::NativesSourceLookup(int index) {
ASSERT(0 <= index && index < Natives::GetBuiltinsCount());
if (Heap::natives_source_cache()->get(index)->IsUndefined()) {
- Handle<String> source_code =
- Factory::NewStringFromAscii(Natives::GetScriptSource(index));
- Heap::natives_source_cache()->set(index, *source_code);
+ if (!Snapshot::IsEnabled || FLAG_new_snapshot) {
+ if (delete_these_non_arrays_on_tear_down == NULL) {
+ delete_these_non_arrays_on_tear_down = new List<char*>(2);
+ }
+ // We can use external strings for the natives.
+ NativesExternalStringResource* resource =
+ new NativesExternalStringResource(
+ Natives::GetScriptSource(index).start());
+ // The resources are small objects and we only make a fixed number of
+ // them, but lets clean them up on exit for neatness.
+ delete_these_non_arrays_on_tear_down->
+ Add(reinterpret_cast<char*>(resource));
+ Handle<String> source_code =
+ Factory::NewExternalStringFromAscii(resource);
+ Heap::natives_source_cache()->set(index, *source_code);
+ } else {
+ // Old snapshot code can't cope with external strings at all.
+ Handle<String> source_code =
+ Factory::NewStringFromAscii(Natives::GetScriptSource(index));
+ Heap::natives_source_cache()->set(index, *source_code);
+ }
}
Handle<Object> cached_source(Heap::natives_source_cache()->get(index));
return Handle<String>::cast(cached_source);
@@ -125,6 +146,16 @@
void Bootstrapper::TearDown() {
+ if (delete_these_non_arrays_on_tear_down != NULL) {
+ int len = delete_these_non_arrays_on_tear_down->length();
+ ASSERT(len < 20); // Don't use this mechanism for unbounded allocations.
+ for (int i = 0; i < len; i++) {
+ delete delete_these_non_arrays_on_tear_down->at(i);
+ }
+ delete delete_these_non_arrays_on_tear_down;
+ delete_these_non_arrays_on_tear_down = NULL;
+ }
+
natives_cache.Initialize(false); // Yes, symmetrical
extensions_cache.Initialize(false);
}
« 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