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

Unified Diff: src/bootstrapper.cc

Issue 911543002: Correctly clean up natives sources on tear down. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years, 10 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 side-by-side diff with in-line comments
Download patch
Index: src/bootstrapper.cc
diff --git a/src/bootstrapper.cc b/src/bootstrapper.cc
index abe6dcc68cd1921e39c67fc2d2cd16f78a76baa2..63223fb66c67b1b0c836bc0c014536dd4c1aa89d 100644
--- a/src/bootstrapper.cc
+++ b/src/bootstrapper.cc
@@ -20,28 +20,10 @@
namespace v8 {
namespace internal {
-NativesExternalStringResource::NativesExternalStringResource(
- Bootstrapper* bootstrapper,
- const char* source,
- size_t length)
- : data_(source), length_(length) {
- if (bootstrapper->delete_these_non_arrays_on_tear_down_ == NULL) {
- bootstrapper->delete_these_non_arrays_on_tear_down_ = new List<char*>(2);
- }
- // The resources are small objects and we only make a fixed number of
- // them, but let's clean them up on exit for neatness.
- bootstrapper->delete_these_non_arrays_on_tear_down_->
- Add(reinterpret_cast<char*>(this));
-}
-
-
Bootstrapper::Bootstrapper(Isolate* isolate)
: isolate_(isolate),
nesting_(0),
- extensions_cache_(Script::TYPE_EXTENSION),
- delete_these_non_arrays_on_tear_down_(NULL),
- delete_these_arrays_on_tear_down_(NULL) {
-}
+ extensions_cache_(Script::TYPE_EXTENSION) {}
Handle<String> Bootstrapper::NativesSourceLookup(int index) {
@@ -51,9 +33,7 @@ Handle<String> Bootstrapper::NativesSourceLookup(int index) {
// We can use external strings for the natives.
Vector<const char> source = Natives::GetScriptSource(index);
NativesExternalStringResource* resource =
- new NativesExternalStringResource(this,
- source.start(),
- source.length());
+ new NativesExternalStringResource(source.start(), source.length());
// We do not expect this to throw an exception. Change this if it does.
Handle<String> source_code = isolate_->factory()
->NewExternalStringFromOneByte(resource)
@@ -114,39 +94,19 @@ void Bootstrapper::TearDownExtensions() {
}
-char* Bootstrapper::AllocateAutoDeletedArray(int bytes) {
- char* memory = new char[bytes];
- if (memory != NULL) {
- if (delete_these_arrays_on_tear_down_ == NULL) {
- delete_these_arrays_on_tear_down_ = new List<char*>(2);
- }
- delete_these_arrays_on_tear_down_->Add(memory);
- }
- return memory;
-}
-
-
void Bootstrapper::TearDown() {
- if (delete_these_non_arrays_on_tear_down_ != NULL) {
- int len = delete_these_non_arrays_on_tear_down_->length();
- DCHECK(len < 1000); // 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_these_non_arrays_on_tear_down_->at(i) = NULL;
- }
- delete delete_these_non_arrays_on_tear_down_;
- delete_these_non_arrays_on_tear_down_ = NULL;
- }
-
- if (delete_these_arrays_on_tear_down_ != NULL) {
- int len = delete_these_arrays_on_tear_down_->length();
- DCHECK(len < 1000); // Don't use this mechanism for unbounded allocations.
- for (int i = 0; i < len; i++) {
- delete[] delete_these_arrays_on_tear_down_->at(i);
- delete_these_arrays_on_tear_down_->at(i) = NULL;
+ Object* natives_source_cache = isolate_->heap()->natives_source_cache();
+ if (natives_source_cache->IsFixedArray()) {
+ FixedArray* natives_source_array = FixedArray::cast(natives_source_cache);
+ for (int i = 0; i < Natives::GetBuiltinsCount(); i++) {
+ Object* natives_source = natives_source_array->get(i);
+ if (!natives_source->IsUndefined()) {
+ const NativesExternalStringResource* resource =
+ reinterpret_cast<const NativesExternalStringResource*>(
+ ExternalOneByteString::cast(natives_source)->resource());
+ delete resource;
+ }
}
- delete delete_these_arrays_on_tear_down_;
- delete_these_arrays_on_tear_down_ = NULL;
}
extensions_cache_.Initialize(isolate_, false); // Yes, symmetrical
« src/bootstrapper.h ('K') | « src/bootstrapper.h ('k') | src/serialize.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698