From 1a7359fb9d75b5c8cf9c4684326a173e9acb98f1 Mon Sep 17 00:00:00 2001 From: "kmillikin@chromium.org" Date: Wed, 11 Mar 2009 12:08:28 +0000 Subject: [PATCH] Deallocate the dynamically-allocated shadow targets that we use for compilation of try/catch and try/finally. Review URL: http://codereview.chromium.org/42068 git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@1489 ce2b1a6d-e550-0410-aec6-3dcde31c8c00 --- src/codegen-arm.cc | 20 +++++++++++--------- src/codegen-ia32.cc | 16 +++++++++------- src/jump-target.h | 2 +- 3 files changed, 21 insertions(+), 17 deletions(-) diff --git a/src/codegen-arm.cc b/src/codegen-arm.cc index 8d9052a2e..7cf3459a2 100644 --- a/src/codegen-arm.cc +++ b/src/codegen-arm.cc @@ -2053,7 +2053,7 @@ void CodeGenerator::VisitTryCatch(TryCatch* node) { // After shadowing stops, the original labels are unshadowed and the // LabelShadows represent the formerly shadowing labels. bool has_unlinks = false; - for (int i = 0; i <= nof_escapes; i++) { + for (int i = 0; i < shadows.length(); i++) { shadows[i]->StopShadowing(); has_unlinks = has_unlinks || shadows[i]->is_linked(); } @@ -2076,8 +2076,8 @@ void CodeGenerator::VisitTryCatch(TryCatch* node) { } // Generate unlink code for the (formerly) shadowing labels that have been - // jumped to. - for (int i = 0; i <= nof_escapes; i++) { + // jumped to. Deallocate each shadow target. + for (int i = 0; i < shadows.length(); i++) { if (shadows[i]->is_linked()) { // Unlink from try chain; shadows[i]->Bind(); @@ -2105,6 +2105,7 @@ void CodeGenerator::VisitTryCatch(TryCatch* node) { } shadows[i]->other_target()->Jump(); } + delete shadows[i]; } exit.Bind(); @@ -2169,7 +2170,7 @@ void CodeGenerator::VisitTryFinally(TryFinally* node) { // After shadowing stops, the original labels are unshadowed and the // LabelShadows represent the formerly shadowing labels. int nof_unlinks = 0; - for (int i = 0; i <= nof_escapes; i++) { + for (int i = 0; i < shadows.length(); i++) { shadows[i]->StopShadowing(); if (shadows[i]->is_linked()) nof_unlinks++; } @@ -2199,8 +2200,8 @@ void CodeGenerator::VisitTryFinally(TryFinally* node) { } // Generate code to unlink and set the state for the (formerly) - // shadowing labels that have been jumped to. - for (int i = 0; i <= nof_escapes; i++) { + // shadowing targets that have been jumped to. + for (int i = 0; i < shadows.length(); i++) { if (shadows[i]->is_linked()) { // If we have come from the shadowed return, the return value is // in (a non-refcounted reference to) r0. We must preserve it @@ -2264,9 +2265,9 @@ void CodeGenerator::VisitTryFinally(TryFinally* node) { frame_->EmitPop(r2); frame_->EmitPop(r0); - // Generate code to jump to the right destination for all used (formerly) - // shadowing labels. - for (int i = 0; i <= nof_escapes; i++) { + // Generate code to jump to the right destination for all used + // formerly shadowing targets. Deallocate each shadow target. + for (int i = 0; i < shadows.length(); i++) { if (shadows[i]->is_bound()) { JumpTarget* original = shadows[i]->other_target(); __ cmp(r2, Operand(Smi::FromInt(JUMPING + i))); @@ -2280,6 +2281,7 @@ void CodeGenerator::VisitTryFinally(TryFinally* node) { original->Branch(eq); } } + delete shadows[i]; } // Check if we need to rethrow the exception. diff --git a/src/codegen-ia32.cc b/src/codegen-ia32.cc index f13af6800..7cc8ed13a 100644 --- a/src/codegen-ia32.cc +++ b/src/codegen-ia32.cc @@ -2718,7 +2718,7 @@ void CodeGenerator::VisitTryCatch(TryCatch* node) { // After shadowing stops, the original targets are unshadowed and the // ShadowTargets represent the formerly shadowing targets. bool has_unlinks = false; - for (int i = 0; i <= nof_escapes; i++) { + for (int i = 0; i < shadows.length(); i++) { shadows[i]->StopShadowing(); has_unlinks = has_unlinks || shadows[i]->is_linked(); } @@ -2749,8 +2749,8 @@ void CodeGenerator::VisitTryCatch(TryCatch* node) { } // Generate unlink code for the (formerly) shadowing targets that have been - // jumped to. - for (int i = 0; i <= nof_escapes; i++) { + // jumped to. Deallocate each shadow target. + for (int i = 0; i < shadows.length(); i++) { if (shadows[i]->is_linked()) { // Unlink from try chain; be careful not to destroy the TOS. shadows[i]->Bind(); @@ -2775,6 +2775,7 @@ void CodeGenerator::VisitTryCatch(TryCatch* node) { } shadows[i]->other_target()->Jump(); } + delete shadows[i]; } exit.Bind(); @@ -2837,7 +2838,7 @@ void CodeGenerator::VisitTryFinally(TryFinally* node) { // After shadowing stops, the original targets are unshadowed and the // ShadowTargets represent the formerly shadowing targets. int nof_unlinks = 0; - for (int i = 0; i <= nof_escapes; i++) { + for (int i = 0; i < shadows.length(); i++) { shadows[i]->StopShadowing(); if (shadows[i]->is_linked()) nof_unlinks++; } @@ -2866,7 +2867,7 @@ void CodeGenerator::VisitTryFinally(TryFinally* node) { // Generate code to unlink and set the state for the (formerly) // shadowing targets that have been jumped to. - for (int i = 0; i <= nof_escapes; i++) { + for (int i = 0; i < shadows.length(); i++) { if (shadows[i]->is_linked()) { // If we have come from the shadowed return, the return value is // in (a non-refcounted reference to) eax. We must preserve it @@ -2926,8 +2927,8 @@ void CodeGenerator::VisitTryFinally(TryFinally* node) { frame_->EmitPop(eax); // Generate code to jump to the right destination for all used - // formerly shadowing targets. - for (int i = 0; i <= nof_escapes; i++) { + // formerly shadowing targets. Deallocate each shadow target. + for (int i = 0; i < shadows.length(); i++) { if (shadows[i]->is_bound()) { JumpTarget* original = shadows[i]->other_target(); __ cmp(Operand(ecx), Immediate(Smi::FromInt(JUMPING + i))); @@ -2941,6 +2942,7 @@ void CodeGenerator::VisitTryFinally(TryFinally* node) { original->Branch(equal); } } + delete shadows[i]; } // Check if we need to rethrow the exception. diff --git a/src/jump-target.h b/src/jump-target.h index 1379ca64e..bf4fc99e2 100644 --- a/src/jump-target.h +++ b/src/jump-target.h @@ -48,7 +48,7 @@ namespace v8 { namespace internal { // In particular, this means that at least one of the control-flow // graph edges reaching the target must be a forward edge. -class JumpTarget : public ZoneObject { // Shadows are dynamically allocated. +class JumpTarget : public Malloced { // Shadows are dynamically allocated. public: // Forward-only jump targets can only be reached by forward CFG edges. enum Directionality { FORWARD_ONLY, BIDIRECTIONAL }; -- 2.34.1