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

Side by Side 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: Rewrote ApiScope unwinding functions, in-lined them. 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 unified diff | Download patch | Annotate | Revision Log
« 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 »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 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. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #include "include/dart_api.h" 5 #include "include/dart_api.h"
6 6
7 #include "vm/bigint_operations.h" 7 #include "vm/bigint_operations.h"
8 #include "vm/class_finalizer.h" 8 #include "vm/class_finalizer.h"
9 #include "vm/compiler.h" 9 #include "vm/compiler.h"
10 #include "vm/dart.h" 10 #include "vm/dart.h"
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after
193 193
194 Dart_Handle Api::NewError(const char* format, ...) { 194 Dart_Handle Api::NewError(const char* format, ...) {
195 Isolate* isolate = Isolate::Current(); 195 Isolate* isolate = Isolate::Current();
196 DARTSCOPE_NOCHECKS(isolate); 196 DARTSCOPE_NOCHECKS(isolate);
197 197
198 va_list args; 198 va_list args;
199 va_start(args, format); 199 va_start(args, format);
200 intptr_t len = OS::VSNPrint(NULL, 0, format, args); 200 intptr_t len = OS::VSNPrint(NULL, 0, format, args);
201 va_end(args); 201 va_end(args);
202 202
203 char* buffer = zone.Alloc<char>(len + 1); 203 char* buffer = isolate->current_zone()->Alloc<char>(len + 1);
204 va_list args2; 204 va_list args2;
205 va_start(args2, format); 205 va_start(args2, format);
206 OS::VSNPrint(buffer, (len + 1), format, args2); 206 OS::VSNPrint(buffer, (len + 1), format, args2);
207 va_end(args2); 207 va_end(args2);
208 208
209 const String& message = String::Handle(isolate, String::New(buffer)); 209 const String& message = String::Handle(isolate, String::New(buffer));
210 return Api::NewHandle(isolate, ApiError::New(message)); 210 return Api::NewHandle(isolate, ApiError::New(message));
211 } 211 }
212 212
213 213
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after
403 // TODO(turnidge): Remove all uses and delete. 403 // TODO(turnidge): Remove all uses and delete.
404 DART_EXPORT Dart_Handle Dart_Error(const char* format, ...) { 404 DART_EXPORT Dart_Handle Dart_Error(const char* format, ...) {
405 Isolate* isolate = Isolate::Current(); 405 Isolate* isolate = Isolate::Current();
406 DARTSCOPE(isolate); 406 DARTSCOPE(isolate);
407 407
408 va_list args; 408 va_list args;
409 va_start(args, format); 409 va_start(args, format);
410 intptr_t len = OS::VSNPrint(NULL, 0, format, args); 410 intptr_t len = OS::VSNPrint(NULL, 0, format, args);
411 va_end(args); 411 va_end(args);
412 412
413 char* buffer = zone.Alloc<char>(len + 1); 413 char* buffer = isolate->current_zone()->Alloc<char>(len + 1);
414 va_list args2; 414 va_list args2;
415 va_start(args2, format); 415 va_start(args2, format);
416 OS::VSNPrint(buffer, (len + 1), format, args2); 416 OS::VSNPrint(buffer, (len + 1), format, args2);
417 va_end(args2); 417 va_end(args2);
418 418
419 const String& message = String::Handle(isolate, String::New(buffer)); 419 const String& message = String::Handle(isolate, String::New(buffer));
420 return Api::NewHandle(isolate, ApiError::New(message)); 420 return Api::NewHandle(isolate, ApiError::New(message));
421 } 421 }
422 422
423 423
424 // TODO(turnidge): This clones Api::NewError. I need to use va_copy to 424 // TODO(turnidge): This clones Api::NewError. I need to use va_copy to
425 // fix this but not sure if it available on all of our builds. 425 // fix this but not sure if it available on all of our builds.
426 DART_EXPORT Dart_Handle Dart_NewApiError(const char* format, ...) { 426 DART_EXPORT Dart_Handle Dart_NewApiError(const char* format, ...) {
427 Isolate* isolate = Isolate::Current(); 427 Isolate* isolate = Isolate::Current();
428 DARTSCOPE(isolate); 428 DARTSCOPE(isolate);
429 429
430 va_list args; 430 va_list args;
431 va_start(args, format); 431 va_start(args, format);
432 intptr_t len = OS::VSNPrint(NULL, 0, format, args); 432 intptr_t len = OS::VSNPrint(NULL, 0, format, args);
433 va_end(args); 433 va_end(args);
434 434
435 char* buffer = zone.Alloc<char>(len + 1); 435 char* buffer = isolate->current_zone()->Alloc<char>(len + 1);
436 va_list args2; 436 va_list args2;
437 va_start(args2, format); 437 va_start(args2, format);
438 OS::VSNPrint(buffer, (len + 1), format, args2); 438 OS::VSNPrint(buffer, (len + 1), format, args2);
439 va_end(args2); 439 va_end(args2);
440 440
441 const String& message = String::Handle(isolate, String::New(buffer)); 441 const String& message = String::Handle(isolate, String::New(buffer));
442 return Api::NewHandle(isolate, ApiError::New(message)); 442 return Api::NewHandle(isolate, ApiError::New(message));
443 } 443 }
444 444
445 445
446 DART_EXPORT Dart_Handle Dart_NewUnhandledExceptionError(Dart_Handle exception) { 446 DART_EXPORT Dart_Handle Dart_NewUnhandledExceptionError(Dart_Handle exception) {
447 Isolate* isolate = Isolate::Current(); 447 Isolate* isolate = Isolate::Current();
448 DARTSCOPE(isolate); 448 DARTSCOPE(isolate);
449 const Instance& obj = Api::UnwrapInstanceHandle(isolate, exception); 449 const Instance& obj = Api::UnwrapInstanceHandle(isolate, exception);
450 if (obj.IsNull()) { 450 if (obj.IsNull()) {
451 RETURN_TYPE_ERROR(isolate, exception, Instance); 451 RETURN_TYPE_ERROR(isolate, exception, Instance);
452 } 452 }
453 const Instance& stacktrace = Instance::Handle(isolate); 453 const Instance& stacktrace = Instance::Handle(isolate);
454 return Api::NewHandle(isolate, UnhandledException::New(obj, stacktrace)); 454 return Api::NewHandle(isolate, UnhandledException::New(obj, stacktrace));
455 } 455 }
456 456
457 457
458 DART_EXPORT Dart_Handle Dart_PropagateError(Dart_Handle handle) { 458 DART_EXPORT Dart_Handle Dart_PropagateError(Dart_Handle handle) {
459 Isolate* isolate = Isolate::Current(); 459 Isolate* isolate = Isolate::Current();
460 CHECK_ISOLATE(isolate); 460 {
461 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(handle)); 461 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(handle));
Ivan Posva 2012/10/15 20:32:17 How about adding a comment explaining that we are
Tom Ball 2012/10/15 21:48:47 Done.
462 if (!obj.IsError()) { 462 if (!obj.IsError()) {
463 return Api::NewError( 463 return Api::NewError(
464 "%s expects argument 'handle' to be an error handle. " 464 "%s expects argument 'handle' to be an error handle. "
465 "Did you forget to check Dart_IsError first?", 465 "Did you forget to check Dart_IsError first?",
466 CURRENT_FUNC); 466 CURRENT_FUNC);
467 }
467 } 468 }
468 if (isolate->top_exit_frame_info() == 0) { 469 if (isolate->top_exit_frame_info() == 0) {
469 // There are no dart frames on the stack so it would be illegal to 470 // There are no dart frames on the stack so it would be illegal to
470 // propagate an error here. 471 // propagate an error here.
471 return Api::NewError("No Dart frames on stack, cannot propagate error."); 472 return Api::NewError("No Dart frames on stack, cannot propagate error.");
472 } 473 }
473 474
474 // Unwind all the API scopes till the exit frame before propagating. 475 // Unwind all the API scopes till the exit frame before propagating.
475 ApiState* state = isolate->api_state(); 476 ApiState* state = isolate->api_state();
476 ASSERT(state != NULL); 477 ASSERT(state != NULL);
477 state->UnwindScopes(isolate->top_exit_frame_info()); 478 Object* error;
Ivan Posva 2012/10/15 20:32:17 How about Error*?Then you can avoid the cast below
Tom Ball 2012/10/15 21:48:47 Done.
478 Exceptions::PropagateError(Error::Cast(obj)); 479 {
480 NoGCScope no_gc;
Ivan Posva 2012/10/15 20:32:17 // We need to preserve the error object across the
Tom Ball 2012/10/15 21:48:47 Done.
481 RawObject* raw_obj = Api::UnwrapHandle(handle);
482 state->UnwindScopes(isolate->top_exit_frame_info());
483 error = &Object::Handle(raw_obj);
484 }
485 Exceptions::PropagateError(Error::Cast(*error));
479 UNREACHABLE(); 486 UNREACHABLE();
480
481 return Api::NewError("Cannot reach here. Internal error."); 487 return Api::NewError("Cannot reach here. Internal error.");
482 } 488 }
483 489
484 490
485 DART_EXPORT void _Dart_ReportErrorHandle(const char* file, 491 DART_EXPORT void _Dart_ReportErrorHandle(const char* file,
486 int line, 492 int line,
487 const char* handle, 493 const char* handle,
488 const char* message) { 494 const char* message) {
489 fprintf(stderr, "%s:%d: error handle: '%s':\n '%s'\n", 495 fprintf(stderr, "%s:%d: error handle: '%s':\n '%s'\n",
490 file, line, handle, message); 496 file, line, handle, message);
(...skipping 644 matching lines...) Expand 10 before | Expand all | Expand 10 after
1135 CHECK_ISOLATE_SCOPE(isolate); 1141 CHECK_ISOLATE_SCOPE(isolate);
1136 ApiState* state = isolate->api_state(); 1142 ApiState* state = isolate->api_state();
1137 ApiLocalScope* scope = state->top_scope(); 1143 ApiLocalScope* scope = state->top_scope();
1138 1144
1139 state->set_top_scope(scope->previous()); // Reset top scope to previous. 1145 state->set_top_scope(scope->previous()); // Reset top scope to previous.
1140 delete scope; // Free up the old scope which we have just exited. 1146 delete scope; // Free up the old scope which we have just exited.
1141 } 1147 }
1142 1148
1143 1149
1144 DART_EXPORT uint8_t* Dart_ScopeAllocate(intptr_t size) { 1150 DART_EXPORT uint8_t* Dart_ScopeAllocate(intptr_t size) {
1145 ApiZone* zone; 1151 Zone* zone;
1146 Isolate* isolate = Isolate::Current(); 1152 Isolate* isolate = Isolate::Current();
1147 if (isolate != NULL) { 1153 if (isolate != NULL) {
1148 ApiState* state = isolate->api_state(); 1154 ApiState* state = isolate->api_state();
1149 if (state == NULL) return NULL; 1155 if (state == NULL) return NULL;
1150 ApiLocalScope* scope = state->top_scope(); 1156 ApiLocalScope* scope = state->top_scope();
1151 zone = scope->zone(); 1157 zone = scope->zone();
1152 } else { 1158 } else {
1153 ApiNativeScope* scope = ApiNativeScope::Current(); 1159 ApiNativeScope* scope = ApiNativeScope::Current();
1154 if (scope == NULL) return NULL; 1160 if (scope == NULL) return NULL;
1155 zone = scope->zone(); 1161 zone = scope->zone();
(...skipping 2734 matching lines...) Expand 10 before | Expand all | Expand 10 after
3890 instance.SetNativeField(index, value); 3896 instance.SetNativeField(index, value);
3891 return Api::Success(isolate); 3897 return Api::Success(isolate);
3892 } 3898 }
3893 3899
3894 3900
3895 // --- Exceptions ---- 3901 // --- Exceptions ----
3896 3902
3897 3903
3898 DART_EXPORT Dart_Handle Dart_ThrowException(Dart_Handle exception) { 3904 DART_EXPORT Dart_Handle Dart_ThrowException(Dart_Handle exception) {
3899 Isolate* isolate = Isolate::Current(); 3905 Isolate* isolate = Isolate::Current();
3900 DARTSCOPE(isolate); 3906 CHECK_ISOLATE(isolate);
3901 const Instance& excp = Api::UnwrapInstanceHandle(isolate, exception); 3907 {
3902 if (excp.IsNull()) { 3908 const Instance& excp = Api::UnwrapInstanceHandle(isolate, exception);
3903 RETURN_TYPE_ERROR(isolate, exception, Instance); 3909 if (excp.IsNull()) {
3910 RETURN_TYPE_ERROR(isolate, exception, Instance);
3911 }
3904 } 3912 }
3905 if (isolate->top_exit_frame_info() == 0) { 3913 if (isolate->top_exit_frame_info() == 0) {
3906 // There are no dart frames on the stack so it would be illegal to 3914 // There are no dart frames on the stack so it would be illegal to
3907 // throw an exception here. 3915 // throw an exception here.
3908 return Api::NewError("No Dart frames on stack, cannot throw exception"); 3916 return Api::NewError("No Dart frames on stack, cannot throw exception");
3909 } 3917 }
3910 // Unwind all the API scopes till the exit frame before throwing an 3918 // Unwind all the API scopes till the exit frame before throwing an
3911 // exception. 3919 // exception.
3912 ApiState* state = isolate->api_state(); 3920 ApiState* state = isolate->api_state();
3913 ASSERT(state != NULL); 3921 ASSERT(state != NULL);
3914 state->UnwindScopes(isolate->top_exit_frame_info()); 3922 Object* exc;
3923 {
3924 NoGCScope no_gc;
3925 RawObject* raw_obj = Api::UnwrapHandle(exception);
3926 state->UnwindScopes(isolate->top_exit_frame_info());
3927 exc = &Object::Handle(raw_obj);
3928 }
3929 Exceptions::PropagateError(Error::Cast(*exc));
Ivan Posva 2012/10/15 20:32:17 ?
Tom Ball 2012/10/15 21:48:47 Removed.
3930 const Instance& excp = Api::UnwrapInstanceHandle(isolate, exception);
Ivan Posva 2012/10/15 20:32:17 The exception handle is very likely invalid at thi
Tom Ball 2012/10/15 21:48:47 Fixed reference.
3915 Exceptions::Throw(excp); 3931 Exceptions::Throw(excp);
3916 return Api::NewError("Exception was not thrown, internal error"); 3932 return Api::NewError("Exception was not thrown, internal error");
3917 } 3933 }
3918 3934
3919 3935
3920 DART_EXPORT Dart_Handle Dart_ReThrowException(Dart_Handle exception, 3936 DART_EXPORT Dart_Handle Dart_ReThrowException(Dart_Handle exception,
3921 Dart_Handle stacktrace) { 3937 Dart_Handle stacktrace) {
3922 Isolate* isolate = Isolate::Current(); 3938 Isolate* isolate = Isolate::Current();
3923 CHECK_ISOLATE(isolate); 3939 CHECK_ISOLATE(isolate);
3924 DARTSCOPE(isolate); 3940 {
3925 const Instance& excp = Api::UnwrapInstanceHandle(isolate, exception); 3941 const Instance& excp = Api::UnwrapInstanceHandle(isolate, exception);
3926 if (excp.IsNull()) { 3942 if (excp.IsNull()) {
3927 RETURN_TYPE_ERROR(isolate, exception, Instance); 3943 RETURN_TYPE_ERROR(isolate, exception, Instance);
3928 } 3944 }
3929 const Instance& stk = Api::UnwrapInstanceHandle(isolate, stacktrace); 3945 const Instance& stk = Api::UnwrapInstanceHandle(isolate, stacktrace);
3930 if (stk.IsNull()) { 3946 if (stk.IsNull()) {
3931 RETURN_TYPE_ERROR(isolate, stacktrace, Instance); 3947 RETURN_TYPE_ERROR(isolate, stacktrace, Instance);
3948 }
3932 } 3949 }
3933 if (isolate->top_exit_frame_info() == 0) { 3950 if (isolate->top_exit_frame_info() == 0) {
3934 // There are no dart frames on the stack so it would be illegal to 3951 // There are no dart frames on the stack so it would be illegal to
3935 // throw an exception here. 3952 // throw an exception here.
3936 return Api::NewError("No Dart frames on stack, cannot throw exception"); 3953 return Api::NewError("No Dart frames on stack, cannot throw exception");
3937 } 3954 }
3938 // Unwind all the API scopes till the exit frame before throwing an 3955 // Unwind all the API scopes till the exit frame before throwing an
3939 // exception. 3956 // exception.
3940 ApiState* state = isolate->api_state(); 3957 ApiState* state = isolate->api_state();
3941 ASSERT(state != NULL); 3958 ASSERT(state != NULL);
3942 state->UnwindScopes(isolate->top_exit_frame_info()); 3959 Object* exc;
3960 Object* stk_trace;
3961 {
3962 NoGCScope no_gc;
3963 RawObject* raw_exception = Api::UnwrapHandle(exception);
3964 RawObject* raw_stacktrace = Api::UnwrapHandle(stacktrace);
3965 state->UnwindScopes(isolate->top_exit_frame_info());
3966 exc = &Object::Handle(raw_exception);
3967 stk_trace = &Object::Handle(raw_stacktrace);
3968 }
3969 const Instance& excp = Instance::Cast(*const_cast<Object*>(exc));
3970 const Instance& stk = Instance::Cast(*const_cast<Object*>(stk_trace));
3943 Exceptions::ReThrow(excp, stk); 3971 Exceptions::ReThrow(excp, stk);
3944 return Api::NewError("Exception was not re thrown, internal error"); 3972 return Api::NewError("Exception was not re thrown, internal error");
3945 } 3973 }
3946 3974
3947 3975
3948 // --- Native functions --- 3976 // --- Native functions ---
3949 3977
3950 3978
3951 DART_EXPORT Dart_Handle Dart_GetNativeArgument(Dart_NativeArguments args, 3979 DART_EXPORT Dart_Handle Dart_GetNativeArgument(Dart_NativeArguments args,
3952 int index) { 3980 int index) {
(...skipping 463 matching lines...) Expand 10 before | Expand all | Expand 10 after
4416 4444
4417 DART_EXPORT void Dart_GetPprofSymbolInfo(void** buffer, int* buffer_size) { 4445 DART_EXPORT void Dart_GetPprofSymbolInfo(void** buffer, int* buffer_size) {
4418 Isolate* isolate = Isolate::Current(); 4446 Isolate* isolate = Isolate::Current();
4419 DebugInfo* pprof_symbol_generator = Dart::pprof_symbol_generator(); 4447 DebugInfo* pprof_symbol_generator = Dart::pprof_symbol_generator();
4420 if (pprof_symbol_generator != NULL) { 4448 if (pprof_symbol_generator != NULL) {
4421 DebugInfo::ByteBuffer* debug_region = new DebugInfo::ByteBuffer(); 4449 DebugInfo::ByteBuffer* debug_region = new DebugInfo::ByteBuffer();
4422 ASSERT(debug_region != NULL); 4450 ASSERT(debug_region != NULL);
4423 pprof_symbol_generator->WriteToMemory(debug_region); 4451 pprof_symbol_generator->WriteToMemory(debug_region);
4424 *buffer_size = debug_region->size(); 4452 *buffer_size = debug_region->size();
4425 if (*buffer_size != 0) { 4453 if (*buffer_size != 0) {
4426 ApiZone* zone = Api::TopScope(isolate)->zone(); 4454 Zone* zone = Api::TopScope(isolate)->zone();
4427 *buffer = reinterpret_cast<void*>(zone->AllocUnsafe(*buffer_size)); 4455 *buffer = reinterpret_cast<void*>(zone->AllocUnsafe(*buffer_size));
4428 memmove(*buffer, debug_region->data(), *buffer_size); 4456 memmove(*buffer, debug_region->data(), *buffer_size);
4429 } else { 4457 } else {
4430 *buffer = NULL; 4458 *buffer = NULL;
4431 } 4459 }
4432 delete debug_region; 4460 delete debug_region;
4433 } else { 4461 } else {
4434 *buffer = NULL; 4462 *buffer = NULL;
4435 *buffer_size = 0; 4463 *buffer_size = 0;
4436 } 4464 }
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
4477 } 4505 }
4478 { 4506 {
4479 NoGCScope no_gc; 4507 NoGCScope no_gc;
4480 RawObject* raw_obj = obj.raw(); 4508 RawObject* raw_obj = obj.raw();
4481 isolate->heap()->SetPeer(raw_obj, peer); 4509 isolate->heap()->SetPeer(raw_obj, peer);
4482 } 4510 }
4483 return Api::Success(isolate); 4511 return Api::Success(isolate);
4484 } 4512 }
4485 4513
4486 } // namespace dart 4514 } // namespace dart
OLDNEW
« 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