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

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: Removed double-linking from zone list, code review feedback. 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 RawObject* raw_obj = Api::UnwrapHandle(handle);
Ivan Posva 2012/10/12 23:04:27 Please wrap the area where you keep the raw object
Tom Ball 2012/10/15 17:17:40 Done.
461 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(handle)); 461 {
462 if (!obj.IsError()) { 462 const Object& obj = Object::Handle(isolate, raw_obj);
463 return Api::NewError( 463 if (!obj.IsError()) {
464 "%s expects argument 'handle' to be an error handle. " 464 return Api::NewError(
Ivan Posva 2012/10/12 23:04:27 Which will make you fail here. You are allocating
Tom Ball 2012/10/15 17:17:40 Moved allocation to where you suggested.
465 "Did you forget to check Dart_IsError first?", 465 "%s expects argument 'handle' to be an error handle. "
466 CURRENT_FUNC); 466 "Did you forget to check Dart_IsError first?",
467 CURRENT_FUNC);
468 }
467 } 469 }
468 if (isolate->top_exit_frame_info() == 0) { 470 if (isolate->top_exit_frame_info() == 0) {
469 // There are no dart frames on the stack so it would be illegal to 471 // There are no dart frames on the stack so it would be illegal to
470 // propagate an error here. 472 // propagate an error here.
471 return Api::NewError("No Dart frames on stack, cannot propagate error."); 473 return Api::NewError("No Dart frames on stack, cannot propagate error.");
472 } 474 }
473 475
474 // Unwind all the API scopes till the exit frame before propagating. 476 // Unwind all the API scopes till the exit frame before propagating.
475 ApiState* state = isolate->api_state(); 477 ApiState* state = isolate->api_state();
476 ASSERT(state != NULL); 478 ASSERT(state != NULL);
477 state->UnwindScopes(isolate->top_exit_frame_info()); 479 state->UnwindScopes(isolate->top_exit_frame_info());
Ivan Posva 2012/10/12 23:04:27 Get the raw_obj out of the handle just before unwi
Tom Ball 2012/10/15 17:17:40 Done.
480 const Object& obj = Object::Handle(isolate, raw_obj);
478 Exceptions::PropagateError(Error::Cast(obj)); 481 Exceptions::PropagateError(Error::Cast(obj));
479 UNREACHABLE(); 482 UNREACHABLE();
480 483
481 return Api::NewError("Cannot reach here. Internal error."); 484 return Api::NewError("Cannot reach here. Internal error.");
482 } 485 }
483 486
484 487
485 DART_EXPORT void _Dart_ReportErrorHandle(const char* file, 488 DART_EXPORT void _Dart_ReportErrorHandle(const char* file,
486 int line, 489 int line,
487 const char* handle, 490 const char* handle,
(...skipping 647 matching lines...) Expand 10 before | Expand all | Expand 10 after
1135 CHECK_ISOLATE_SCOPE(isolate); 1138 CHECK_ISOLATE_SCOPE(isolate);
1136 ApiState* state = isolate->api_state(); 1139 ApiState* state = isolate->api_state();
1137 ApiLocalScope* scope = state->top_scope(); 1140 ApiLocalScope* scope = state->top_scope();
1138 1141
1139 state->set_top_scope(scope->previous()); // Reset top scope to previous. 1142 state->set_top_scope(scope->previous()); // Reset top scope to previous.
1140 delete scope; // Free up the old scope which we have just exited. 1143 delete scope; // Free up the old scope which we have just exited.
1141 } 1144 }
1142 1145
1143 1146
1144 DART_EXPORT uint8_t* Dart_ScopeAllocate(intptr_t size) { 1147 DART_EXPORT uint8_t* Dart_ScopeAllocate(intptr_t size) {
1145 ApiZone* zone; 1148 Zone* zone;
1146 Isolate* isolate = Isolate::Current(); 1149 Isolate* isolate = Isolate::Current();
1147 if (isolate != NULL) { 1150 if (isolate != NULL) {
1148 ApiState* state = isolate->api_state(); 1151 ApiState* state = isolate->api_state();
1149 if (state == NULL) return NULL; 1152 if (state == NULL) return NULL;
1150 ApiLocalScope* scope = state->top_scope(); 1153 ApiLocalScope* scope = state->top_scope();
1151 zone = scope->zone(); 1154 zone = scope->zone();
1152 } else { 1155 } else {
1153 ApiNativeScope* scope = ApiNativeScope::Current(); 1156 ApiNativeScope* scope = ApiNativeScope::Current();
1154 if (scope == NULL) return NULL; 1157 if (scope == NULL) return NULL;
1155 zone = scope->zone(); 1158 zone = scope->zone();
(...skipping 2733 matching lines...) Expand 10 before | Expand all | Expand 10 after
3889 instance.SetNativeField(index, value); 3892 instance.SetNativeField(index, value);
3890 return Api::Success(isolate); 3893 return Api::Success(isolate);
3891 } 3894 }
3892 3895
3893 3896
3894 // --- Exceptions ---- 3897 // --- Exceptions ----
3895 3898
3896 3899
3897 DART_EXPORT Dart_Handle Dart_ThrowException(Dart_Handle exception) { 3900 DART_EXPORT Dart_Handle Dart_ThrowException(Dart_Handle exception) {
3898 Isolate* isolate = Isolate::Current(); 3901 Isolate* isolate = Isolate::Current();
3899 DARTSCOPE(isolate); 3902 CHECK_ISOLATE(isolate);
3900 const Instance& excp = Api::UnwrapInstanceHandle(isolate, exception); 3903 {
3901 if (excp.IsNull()) { 3904 const Instance& excp = Api::UnwrapInstanceHandle(isolate, exception);
3902 RETURN_TYPE_ERROR(isolate, exception, Instance); 3905 if (excp.IsNull()) {
3906 RETURN_TYPE_ERROR(isolate, exception, Instance);
3907 }
3903 } 3908 }
3904 if (isolate->top_exit_frame_info() == 0) { 3909 if (isolate->top_exit_frame_info() == 0) {
3905 // There are no dart frames on the stack so it would be illegal to 3910 // There are no dart frames on the stack so it would be illegal to
3906 // throw an exception here. 3911 // throw an exception here.
3907 return Api::NewError("No Dart frames on stack, cannot throw exception"); 3912 return Api::NewError("No Dart frames on stack, cannot throw exception");
3908 } 3913 }
3909 // Unwind all the API scopes till the exit frame before throwing an 3914 // Unwind all the API scopes till the exit frame before throwing an
3910 // exception. 3915 // exception.
3911 ApiState* state = isolate->api_state(); 3916 ApiState* state = isolate->api_state();
3912 ASSERT(state != NULL); 3917 ASSERT(state != NULL);
3918
3919 // Unwind all the API scopes till the exit frame before throwing an
3920 // exception.
3921 RawObject* raw_excp = Api::UnwrapHandle(exception);
Ivan Posva 2012/10/12 23:04:27 NoGCScope while you hold on to raw objects.
3913 state->UnwindScopes(isolate->top_exit_frame_info()); 3922 state->UnwindScopes(isolate->top_exit_frame_info());
3923 const Instance& excp = Instance::Cast(Object::Handle(isolate, raw_excp));
3914 Exceptions::Throw(excp); 3924 Exceptions::Throw(excp);
3915 return Api::NewError("Exception was not thrown, internal error"); 3925 return Api::NewError("Exception was not thrown, internal error");
3916 } 3926 }
3917 3927
3918 3928
3919 DART_EXPORT Dart_Handle Dart_ReThrowException(Dart_Handle exception, 3929 DART_EXPORT Dart_Handle Dart_ReThrowException(Dart_Handle exception,
3920 Dart_Handle stacktrace) { 3930 Dart_Handle stacktrace) {
3921 Isolate* isolate = Isolate::Current(); 3931 Isolate* isolate = Isolate::Current();
3922 CHECK_ISOLATE(isolate); 3932 CHECK_ISOLATE(isolate);
3923 DARTSCOPE(isolate); 3933 {
3924 const Instance& excp = Api::UnwrapInstanceHandle(isolate, exception); 3934 const Instance& excp = Api::UnwrapInstanceHandle(isolate, exception);
3925 if (excp.IsNull()) { 3935 if (excp.IsNull()) {
3926 RETURN_TYPE_ERROR(isolate, exception, Instance); 3936 RETURN_TYPE_ERROR(isolate, exception, Instance);
3927 } 3937 }
3928 const Instance& stk = Api::UnwrapInstanceHandle(isolate, stacktrace); 3938 const Instance& stk = Api::UnwrapInstanceHandle(isolate, stacktrace);
3929 if (stk.IsNull()) { 3939 if (stk.IsNull()) {
3930 RETURN_TYPE_ERROR(isolate, stacktrace, Instance); 3940 RETURN_TYPE_ERROR(isolate, stacktrace, Instance);
3941 }
3931 } 3942 }
3932 if (isolate->top_exit_frame_info() == 0) { 3943 if (isolate->top_exit_frame_info() == 0) {
3933 // There are no dart frames on the stack so it would be illegal to 3944 // There are no dart frames on the stack so it would be illegal to
3934 // throw an exception here. 3945 // throw an exception here.
3935 return Api::NewError("No Dart frames on stack, cannot throw exception"); 3946 return Api::NewError("No Dart frames on stack, cannot throw exception");
3936 } 3947 }
3937 // Unwind all the API scopes till the exit frame before throwing an 3948 // Unwind all the API scopes till the exit frame before throwing an
3938 // exception. 3949 // exception.
3939 ApiState* state = isolate->api_state(); 3950 ApiState* state = isolate->api_state();
3940 ASSERT(state != NULL); 3951 ASSERT(state != NULL);
3952 RawObject* raw_excp = Api::UnwrapHandle(exception);
Ivan Posva 2012/10/12 23:04:27 ditto: NoGCScope is needed.
3953 RawObject* raw_stk = Api::UnwrapHandle(stacktrace);
3941 state->UnwindScopes(isolate->top_exit_frame_info()); 3954 state->UnwindScopes(isolate->top_exit_frame_info());
3955 const Instance& excp = Instance::Cast(Object::Handle(isolate, raw_excp));
3956 const Instance& stk = Instance::Cast(Object::Handle(isolate, raw_stk));
3942 Exceptions::ReThrow(excp, stk); 3957 Exceptions::ReThrow(excp, stk);
3943 return Api::NewError("Exception was not re thrown, internal error"); 3958 return Api::NewError("Exception was not re thrown, internal error");
3944 } 3959 }
3945 3960
3946 3961
3947 // --- Native functions --- 3962 // --- Native functions ---
3948 3963
3949 3964
3950 DART_EXPORT Dart_Handle Dart_GetNativeArgument(Dart_NativeArguments args, 3965 DART_EXPORT Dart_Handle Dart_GetNativeArgument(Dart_NativeArguments args,
3951 int index) { 3966 int index) {
(...skipping 463 matching lines...) Expand 10 before | Expand all | Expand 10 after
4415 4430
4416 DART_EXPORT void Dart_GetPprofSymbolInfo(void** buffer, int* buffer_size) { 4431 DART_EXPORT void Dart_GetPprofSymbolInfo(void** buffer, int* buffer_size) {
4417 Isolate* isolate = Isolate::Current(); 4432 Isolate* isolate = Isolate::Current();
4418 DebugInfo* pprof_symbol_generator = Dart::pprof_symbol_generator(); 4433 DebugInfo* pprof_symbol_generator = Dart::pprof_symbol_generator();
4419 if (pprof_symbol_generator != NULL) { 4434 if (pprof_symbol_generator != NULL) {
4420 DebugInfo::ByteBuffer* debug_region = new DebugInfo::ByteBuffer(); 4435 DebugInfo::ByteBuffer* debug_region = new DebugInfo::ByteBuffer();
4421 ASSERT(debug_region != NULL); 4436 ASSERT(debug_region != NULL);
4422 pprof_symbol_generator->WriteToMemory(debug_region); 4437 pprof_symbol_generator->WriteToMemory(debug_region);
4423 *buffer_size = debug_region->size(); 4438 *buffer_size = debug_region->size();
4424 if (*buffer_size != 0) { 4439 if (*buffer_size != 0) {
4425 ApiZone* zone = Api::TopScope(isolate)->zone(); 4440 Zone* zone = Api::TopScope(isolate)->zone();
4426 *buffer = reinterpret_cast<void*>(zone->AllocUnsafe(*buffer_size)); 4441 *buffer = reinterpret_cast<void*>(zone->AllocUnsafe(*buffer_size));
4427 memmove(*buffer, debug_region->data(), *buffer_size); 4442 memmove(*buffer, debug_region->data(), *buffer_size);
4428 } else { 4443 } else {
4429 *buffer = NULL; 4444 *buffer = NULL;
4430 } 4445 }
4431 delete debug_region; 4446 delete debug_region;
4432 } else { 4447 } else {
4433 *buffer = NULL; 4448 *buffer = NULL;
4434 *buffer_size = 0; 4449 *buffer_size = 0;
4435 } 4450 }
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
4476 } 4491 }
4477 { 4492 {
4478 NoGCScope no_gc; 4493 NoGCScope no_gc;
4479 RawObject* raw_obj = obj.raw(); 4494 RawObject* raw_obj = obj.raw();
4480 isolate->heap()->SetPeer(raw_obj, peer); 4495 isolate->heap()->SetPeer(raw_obj, peer);
4481 } 4496 }
4482 return Api::Success(isolate); 4497 return Api::Success(isolate);
4483 } 4498 }
4484 4499
4485 } // namespace dart 4500 } // 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