[vm] Use handles instead of array allocation when executing catch entry moves

Issue https://github.com/dart-lang/sdk/issues/43543

Change-Id: I61472be2507ce97721ab162a8c86f9662ec27f72
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/164540
Commit-Queue: Martin Kustermann <kustermann@google.com>
Reviewed-by: Ryan Macnak <rmacnak@google.com>
This commit is contained in:
Ryan Macnak 2020-10-02 15:59:18 +00:00 committed by commit-bot@chromium.org
parent 7704cc9dbe
commit 7d79d215db
3 changed files with 55 additions and 5 deletions

View file

@ -252,7 +252,7 @@ class ExceptionHandlerFinder : public StackResource {
void ExecuteCatchEntryMoves(const CatchEntryMoves& moves) {
Zone* zone = Thread::Current()->zone();
auto& value = Object::Handle(zone);
auto& dst_values = Array::Handle(zone, Array::New(moves.count()));
GrowableArray<Object*> dst_values;
uword fp = handler_fp;
ObjectPool* pool = nullptr;
@ -309,7 +309,7 @@ class ExceptionHandlerFinder : public StackResource {
UNREACHABLE();
}
dst_values.SetAt(j, value);
dst_values.Add(&Object::Handle(zone, value.raw()));
}
{
@ -317,8 +317,7 @@ class ExceptionHandlerFinder : public StackResource {
for (int j = 0; j < moves.count(); j++) {
const CatchEntryMove& move = moves.At(j);
value = dst_values.At(j);
*TaggedSlotAt(fp, move.dest_slot()) = value.raw();
*TaggedSlotAt(fp, move.dest_slot()) = dst_values[j]->raw();
}
}
}
@ -879,7 +878,10 @@ static void ThrowExceptionHelper(Thread* thread,
// the isolate etc.). This can happen in the compiler, which is not
// allowed to allocate in new space, so we pass the kOld argument.
const UnhandledException& unhandled_exception = UnhandledException::Handle(
zone, UnhandledException::New(exception, stacktrace, Heap::kOld));
zone, exception.raw() == isolate->object_store()->out_of_memory()
? isolate->isolate_object_store()
->preallocated_unhandled_exception()
: UnhandledException::New(exception, stacktrace, Heap::kOld));
stacktrace = StackTrace::null();
JumpToExceptionHandler(thread, handler_pc, handler_sp, handler_fp,
unhandled_exception, stacktrace);

View file

@ -0,0 +1,24 @@
// Copyright (c) 2020, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// VMOptions=--old_gen_heap_size=20
// VMOptions=--old_gen_heap_size=20 --enable_vm_service --pause_isolates_on_unhandled_exceptions
import "package:expect/expect.dart";
main() {
var leak;
var exceptionThrown = false;
try {
leak = [];
while (true) {
leak = [leak];
}
} on OutOfMemoryError catch (exception) {
leak = null;
exceptionThrown = true;
print("Okay");
}
Expect.isTrue(exceptionThrown);
}

View file

@ -0,0 +1,24 @@
// Copyright (c) 2020, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// VMOptions=--old_gen_heap_size=20
// VMOptions=--old_gen_heap_size=20 --enable_vm_service --pause_isolates_on_unhandled_exceptions
import "package:expect/expect.dart";
main() {
var leak;
var exceptionThrown = false;
try {
leak = [];
while (true) {
leak = [leak];
}
} on OutOfMemoryError catch (exception) {
leak = null;
exceptionThrown = true;
print("Okay");
}
Expect.isTrue(exceptionThrown);
}