[VM] Do not invoke the empty StackOverflowError/OutOfMemoryError constructors
Issue https://github.com/dart-lang/sdk/issues/33185
Change-Id: If5bf7269cede7ed4a643bc338c964dacdc03cdaf
Reviewed-on: https://dart-review.googlesource.com/56324
Reviewed-by: Vyacheslav Egorov <vegorov@google.com>
diff --git a/runtime/vm/object_store.cc b/runtime/vm/object_store.cc
index 43b9a5c..2d62110 100644
--- a/runtime/vm/object_store.cc
+++ b/runtime/vm/object_store.cc
@@ -57,6 +57,13 @@
}
#endif // !PRODUCT
+static RawInstance* AllocateObjectByClassName(const Library& library,
+ const String& class_name) {
+ const Class& cls = Class::Handle(library.LookupClassAllowPrivate(class_name));
+ ASSERT(!cls.IsNull());
+ return Instance::New(cls);
+}
+
RawError* ObjectStore::PreallocateObjects() {
Thread* thread = Thread::Current();
Isolate* isolate = thread->isolate();
@@ -81,17 +88,13 @@
Object& result = Object::Handle();
const Library& library = Library::Handle(Library::CoreLibrary());
- result =
- DartLibraryCalls::InstanceCreate(library, Symbols::StackOverflowError(),
- Symbols::Dot(), Object::empty_array());
+ result = AllocateObjectByClassName(library, Symbols::StackOverflowError());
if (result.IsError()) {
return Error::Cast(result).raw();
}
set_stack_overflow(Instance::Cast(result));
- result =
- DartLibraryCalls::InstanceCreate(library, Symbols::OutOfMemoryError(),
- Symbols::Dot(), Object::empty_array());
+ result = AllocateObjectByClassName(library, Symbols::OutOfMemoryError());
if (result.IsError()) {
return Error::Cast(result).raw();
}