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

Unified Diff: runtime/vm/dart_api_impl.cc

Issue 11028145: Changed StackZone and ApiZone to be containers for Zone. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Reworked ApiScope unwinding. Created 8 years, 2 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
« no previous file with comments | « runtime/vm/code_descriptors_test.cc ('k') | runtime/vm/dart_api_impl_test.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/vm/dart_api_impl.cc
diff --git a/runtime/vm/dart_api_impl.cc b/runtime/vm/dart_api_impl.cc
index 1400d12c093615a09a15ea4494aac94cece0ee06..ed7beae09b4e637e17ab2a575d29b1555a2bc9e9 100644
--- a/runtime/vm/dart_api_impl.cc
+++ b/runtime/vm/dart_api_impl.cc
@@ -200,7 +200,7 @@ Dart_Handle Api::NewError(const char* format, ...) {
intptr_t len = OS::VSNPrint(NULL, 0, format, args);
va_end(args);
- char* buffer = zone.Alloc<char>(len + 1);
+ char* buffer = isolate->current_zone()->Alloc<char>(len + 1);
va_list args2;
va_start(args2, format);
OS::VSNPrint(buffer, (len + 1), format, args2);
@@ -410,7 +410,7 @@ DART_EXPORT Dart_Handle Dart_Error(const char* format, ...) {
intptr_t len = OS::VSNPrint(NULL, 0, format, args);
va_end(args);
- char* buffer = zone.Alloc<char>(len + 1);
+ char* buffer = isolate->current_zone()->Alloc<char>(len + 1);
va_list args2;
va_start(args2, format);
OS::VSNPrint(buffer, (len + 1), format, args2);
@@ -432,7 +432,7 @@ DART_EXPORT Dart_Handle Dart_NewApiError(const char* format, ...) {
intptr_t len = OS::VSNPrint(NULL, 0, format, args);
va_end(args);
- char* buffer = zone.Alloc<char>(len + 1);
+ char* buffer = isolate->current_zone()->Alloc<char>(len + 1);
va_list args2;
va_start(args2, format);
OS::VSNPrint(buffer, (len + 1), format, args2);
@@ -455,15 +455,27 @@ DART_EXPORT Dart_Handle Dart_NewUnhandledExceptionError(Dart_Handle exception) {
}
+// Unwind all the API scopes till the exit frame, and reallocate handle.
+DART_EXPORT Dart_Handle UnwindApiScopes(Isolate* isolate, Dart_Handle handle) {
siva 2012/10/15 17:50:35 Why not make this a static method?
Ivan Posva 2012/10/15 18:26:01 There should be no need to return a Dart_Handle he
Tom Ball 2012/10/15 19:51:06 Done.
Tom Ball 2012/10/15 19:51:06 Inlined function.
+ NoGCScope no_gc;
+ ApiState* state = isolate->api_state();
+ ASSERT(state != NULL);
+ RawObject* raw_obj = Api::UnwrapHandle(handle);
+ state->UnwindScopes(isolate->top_exit_frame_info());
+ return Api::NewHandle(isolate, raw_obj);
siva 2012/10/15 17:50:35 These new handles are created in the outer API sco
Tom Ball 2012/10/15 19:51:06 Removed function, as Ivan described.
+}
+
+
DART_EXPORT Dart_Handle Dart_PropagateError(Dart_Handle handle) {
Isolate* isolate = Isolate::Current();
- CHECK_ISOLATE(isolate);
- const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(handle));
- if (!obj.IsError()) {
- return Api::NewError(
- "%s expects argument 'handle' to be an error handle. "
- "Did you forget to check Dart_IsError first?",
- CURRENT_FUNC);
+ {
+ const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(handle));
+ if (!obj.IsError()) {
+ return Api::NewError(
+ "%s expects argument 'handle' to be an error handle. "
+ "Did you forget to check Dart_IsError first?",
+ CURRENT_FUNC);
+ }
}
if (isolate->top_exit_frame_info() == 0) {
// There are no dart frames on the stack so it would be illegal to
@@ -472,12 +484,10 @@ DART_EXPORT Dart_Handle Dart_PropagateError(Dart_Handle handle) {
}
// Unwind all the API scopes till the exit frame before propagating.
- ApiState* state = isolate->api_state();
- ASSERT(state != NULL);
- state->UnwindScopes(isolate->top_exit_frame_info());
+ handle = UnwindApiScopes(isolate, handle);
Ivan Posva 2012/10/15 18:26:01 This avoids Siva's concern: ASSERT(state != NUL
Tom Ball 2012/10/15 19:51:06 Integrated recommended change.
+ const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(handle));
Exceptions::PropagateError(Error::Cast(obj));
UNREACHABLE();
-
return Api::NewError("Cannot reach here. Internal error.");
}
@@ -1142,7 +1152,7 @@ DART_EXPORT void Dart_ExitScope() {
DART_EXPORT uint8_t* Dart_ScopeAllocate(intptr_t size) {
- ApiZone* zone;
+ Zone* zone;
Isolate* isolate = Isolate::Current();
if (isolate != NULL) {
ApiState* state = isolate->api_state();
@@ -3896,10 +3906,12 @@ DART_EXPORT Dart_Handle Dart_SetNativeInstanceField(Dart_Handle obj,
DART_EXPORT Dart_Handle Dart_ThrowException(Dart_Handle exception) {
Isolate* isolate = Isolate::Current();
- DARTSCOPE(isolate);
- const Instance& excp = Api::UnwrapInstanceHandle(isolate, exception);
- if (excp.IsNull()) {
- RETURN_TYPE_ERROR(isolate, exception, Instance);
+ CHECK_ISOLATE(isolate);
+ {
+ const Instance& excp = Api::UnwrapInstanceHandle(isolate, exception);
+ if (excp.IsNull()) {
+ RETURN_TYPE_ERROR(isolate, exception, Instance);
+ }
}
if (isolate->top_exit_frame_info() == 0) {
// There are no dart frames on the stack so it would be illegal to
@@ -3910,24 +3922,44 @@ DART_EXPORT Dart_Handle Dart_ThrowException(Dart_Handle exception) {
// exception.
ApiState* state = isolate->api_state();
ASSERT(state != NULL);
- state->UnwindScopes(isolate->top_exit_frame_info());
+
+ // Unwind all the API scopes till the exit frame before throwing an
+ // exception.
+ exception = UnwindApiScopes(isolate, exception);
+ const Instance& excp = Api::UnwrapInstanceHandle(isolate, exception);
Exceptions::Throw(excp);
return Api::NewError("Exception was not thrown, internal error");
}
+// Unwind all the API scopes till the exit frame before rethrowing an exception.
+DART_EXPORT void UnwindApiScopesForRethrow(Isolate* isolate,
+ Dart_Handle* exception,
+ Dart_Handle* stacktrace) {
siva 2012/10/15 17:50:35 Ditto, why not make this a static method.
Tom Ball 2012/10/15 19:51:06 Inlined code and removed function.
+ NoGCScope no_gc;
+ ApiState* state = isolate->api_state();
+ ASSERT(state != NULL);
+ RawObject* raw_excp = Api::UnwrapHandle(*exception);
+ RawObject* raw_stk = Api::UnwrapHandle(*stacktrace);
+ state->UnwindScopes(isolate->top_exit_frame_info());
+ *exception = Api::NewHandle(isolate, raw_excp);
Ivan Posva 2012/10/15 18:26:01 No Dart_Handles as they can leak out.
Tom Ball 2012/10/15 19:51:06 Removed, followed pattern you recommended for Prop
+ *stacktrace = Api::NewHandle(isolate, raw_stk);
+}
+
+
DART_EXPORT Dart_Handle Dart_ReThrowException(Dart_Handle exception,
Dart_Handle stacktrace) {
Isolate* isolate = Isolate::Current();
CHECK_ISOLATE(isolate);
- DARTSCOPE(isolate);
- const Instance& excp = Api::UnwrapInstanceHandle(isolate, exception);
- if (excp.IsNull()) {
- RETURN_TYPE_ERROR(isolate, exception, Instance);
- }
- const Instance& stk = Api::UnwrapInstanceHandle(isolate, stacktrace);
- if (stk.IsNull()) {
- RETURN_TYPE_ERROR(isolate, stacktrace, Instance);
+ {
+ const Instance& excp = Api::UnwrapInstanceHandle(isolate, exception);
+ if (excp.IsNull()) {
+ RETURN_TYPE_ERROR(isolate, exception, Instance);
+ }
+ const Instance& stk = Api::UnwrapInstanceHandle(isolate, stacktrace);
+ if (stk.IsNull()) {
+ RETURN_TYPE_ERROR(isolate, stacktrace, Instance);
+ }
}
if (isolate->top_exit_frame_info() == 0) {
// There are no dart frames on the stack so it would be illegal to
@@ -3938,7 +3970,9 @@ DART_EXPORT Dart_Handle Dart_ReThrowException(Dart_Handle exception,
// exception.
ApiState* state = isolate->api_state();
ASSERT(state != NULL);
- state->UnwindScopes(isolate->top_exit_frame_info());
+ UnwindApiScopesForRethrow(isolate, &exception, &stacktrace);
+ const Instance& excp = Api::UnwrapInstanceHandle(isolate, exception);
+ const Instance& stk = Api::UnwrapInstanceHandle(isolate, stacktrace);
Exceptions::ReThrow(excp, stk);
return Api::NewError("Exception was not re thrown, internal error");
}
@@ -4422,7 +4456,7 @@ DART_EXPORT void Dart_GetPprofSymbolInfo(void** buffer, int* buffer_size) {
pprof_symbol_generator->WriteToMemory(debug_region);
*buffer_size = debug_region->size();
if (*buffer_size != 0) {
- ApiZone* zone = Api::TopScope(isolate)->zone();
+ Zone* zone = Api::TopScope(isolate)->zone();
*buffer = reinterpret_cast<void*>(zone->AllocUnsafe(*buffer_size));
memmove(*buffer, debug_region->data(), *buffer_size);
} else {
« no previous file with comments | « runtime/vm/code_descriptors_test.cc ('k') | runtime/vm/dart_api_impl_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698