Skip to content

Commit 7d79d21

Browse files
rmacnak-googlecommit-bot@chromium.org
authored andcommitted
[vm] Use handles instead of array allocation when executing catch entry moves
Issue dart-lang#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>
1 parent 7704cc9 commit 7d79d21

File tree

3 files changed

+55
-5
lines changed

3 files changed

+55
-5
lines changed

runtime/vm/exceptions.cc

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ class ExceptionHandlerFinder : public StackResource {
252252
void ExecuteCatchEntryMoves(const CatchEntryMoves& moves) {
253253
Zone* zone = Thread::Current()->zone();
254254
auto& value = Object::Handle(zone);
255-
auto& dst_values = Array::Handle(zone, Array::New(moves.count()));
255+
GrowableArray<Object*> dst_values;
256256

257257
uword fp = handler_fp;
258258
ObjectPool* pool = nullptr;
@@ -309,16 +309,15 @@ class ExceptionHandlerFinder : public StackResource {
309309
UNREACHABLE();
310310
}
311311

312-
dst_values.SetAt(j, value);
312+
dst_values.Add(&Object::Handle(zone, value.raw()));
313313
}
314314

315315
{
316316
NoSafepointScope no_safepoint_scope;
317317

318318
for (int j = 0; j < moves.count(); j++) {
319319
const CatchEntryMove& move = moves.At(j);
320-
value = dst_values.At(j);
321-
*TaggedSlotAt(fp, move.dest_slot()) = value.raw();
320+
*TaggedSlotAt(fp, move.dest_slot()) = dst_values[j]->raw();
322321
}
323322
}
324323
}
@@ -879,7 +878,10 @@ static void ThrowExceptionHelper(Thread* thread,
879878
// the isolate etc.). This can happen in the compiler, which is not
880879
// allowed to allocate in new space, so we pass the kOld argument.
881880
const UnhandledException& unhandled_exception = UnhandledException::Handle(
882-
zone, UnhandledException::New(exception, stacktrace, Heap::kOld));
881+
zone, exception.raw() == isolate->object_store()->out_of_memory()
882+
? isolate->isolate_object_store()
883+
->preallocated_unhandled_exception()
884+
: UnhandledException::New(exception, stacktrace, Heap::kOld));
883885
stacktrace = StackTrace::null();
884886
JumpToExceptionHandler(thread, handler_pc, handler_sp, handler_fp,
885887
unhandled_exception, stacktrace);
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// Copyright (c) 2020, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
// VMOptions=--old_gen_heap_size=20
6+
// VMOptions=--old_gen_heap_size=20 --enable_vm_service --pause_isolates_on_unhandled_exceptions
7+
8+
import "package:expect/expect.dart";
9+
10+
main() {
11+
var leak;
12+
var exceptionThrown = false;
13+
try {
14+
leak = [];
15+
while (true) {
16+
leak = [leak];
17+
}
18+
} on OutOfMemoryError catch (exception) {
19+
leak = null;
20+
exceptionThrown = true;
21+
print("Okay");
22+
}
23+
Expect.isTrue(exceptionThrown);
24+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// Copyright (c) 2020, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
// VMOptions=--old_gen_heap_size=20
6+
// VMOptions=--old_gen_heap_size=20 --enable_vm_service --pause_isolates_on_unhandled_exceptions
7+
8+
import "package:expect/expect.dart";
9+
10+
main() {
11+
var leak;
12+
var exceptionThrown = false;
13+
try {
14+
leak = [];
15+
while (true) {
16+
leak = [leak];
17+
}
18+
} on OutOfMemoryError catch (exception) {
19+
leak = null;
20+
exceptionThrown = true;
21+
print("Okay");
22+
}
23+
Expect.isTrue(exceptionThrown);
24+
}

0 commit comments

Comments
 (0)