| OLD | NEW |
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, 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 "vm/longjump.h" | 5 #include "vm/longjump.h" |
| 6 | 6 |
| 7 #include "include/dart_api.h" | 7 #include "include/dart_api.h" |
| 8 | 8 |
| 9 #include "vm/dart_api_impl.h" | 9 #include "vm/dart_api_impl.h" |
| 10 #include "vm/isolate.h" | 10 #include "vm/isolate.h" |
| 11 #include "vm/object.h" | 11 #include "vm/object.h" |
| 12 #include "vm/object_store.h" | 12 #include "vm/object_store.h" |
| 13 #include "vm/os.h" | 13 #include "vm/os.h" |
| 14 #include "vm/simulator.h" | 14 #include "vm/simulator.h" |
| 15 | 15 |
| 16 namespace dart { | 16 namespace dart { |
| 17 | 17 |
| 18 jmp_buf* LongJump::Set() { | 18 jmp_buf* LongJumpScope::Set() { |
| 19 ASSERT(top_ == NULL); |
| 19 top_ = Isolate::Current()->top_resource(); | 20 top_ = Isolate::Current()->top_resource(); |
| 20 return &environment_; | 21 return &environment_; |
| 21 } | 22 } |
| 22 | 23 |
| 23 | 24 |
| 24 bool LongJump::IsSafeToJump() { | 25 bool LongJumpScope::IsSafeToJump() { |
| 25 // We do not want to jump past Dart frames. Note that this code | 26 // We do not want to jump past Dart frames. Note that this code |
| 26 // assumes the stack grows from high to low. | 27 // assumes the stack grows from high to low. |
| 27 Isolate* isolate = Isolate::Current(); | 28 Isolate* isolate = Isolate::Current(); |
| 28 uword jumpbuf_addr = reinterpret_cast<uword>(this); | 29 uword jumpbuf_addr = reinterpret_cast<uword>(this); |
| 29 #if defined(USING_SIMULATOR) | 30 #if defined(USING_SIMULATOR) |
| 30 uword top_exit_frame_info = isolate->simulator()->top_exit_frame_info(); | 31 uword top_exit_frame_info = isolate->simulator()->top_exit_frame_info(); |
| 31 #else | 32 #else |
| 32 uword top_exit_frame_info = isolate->top_exit_frame_info(); | 33 uword top_exit_frame_info = isolate->top_exit_frame_info(); |
| 33 #endif | 34 #endif |
| 34 return ((top_exit_frame_info == 0) || (jumpbuf_addr < top_exit_frame_info)); | 35 return ((top_exit_frame_info == 0) || (jumpbuf_addr < top_exit_frame_info)); |
| 35 } | 36 } |
| 36 | 37 |
| 37 | 38 |
| 38 void LongJump::Jump(int value, const Error& error) { | 39 void LongJumpScope::Jump(int value, const Error& error) { |
| 39 // A zero is the default return value from setting up a LongJump using Set. | 40 // A zero is the default return value from setting up a LongJumpScope |
| 41 // using Set. |
| 40 ASSERT(value != 0); | 42 ASSERT(value != 0); |
| 41 ASSERT(IsSafeToJump()); | 43 ASSERT(IsSafeToJump()); |
| 42 | 44 |
| 43 Isolate* isolate = Isolate::Current(); | 45 Isolate* isolate = Isolate::Current(); |
| 44 | 46 |
| 45 // Remember the error in the sticky error of this isolate. | 47 // Remember the error in the sticky error of this isolate. |
| 46 isolate->object_store()->set_sticky_error(error); | 48 isolate->object_store()->set_sticky_error(error); |
| 47 | 49 |
| 48 // Destruct all the active StackResource objects. | 50 // Destruct all the active StackResource objects. |
| 49 StackResource* current_resource = isolate->top_resource(); | 51 StackResource* current_resource = isolate->top_resource(); |
| 50 while (current_resource != top_) { | 52 while (current_resource != top_) { |
| 51 current_resource->~StackResource(); | 53 current_resource->~StackResource(); |
| 52 current_resource = isolate->top_resource(); | 54 current_resource = isolate->top_resource(); |
| 53 } | 55 } |
| 54 longjmp(environment_, value); | 56 longjmp(environment_, value); |
| 55 UNREACHABLE(); | 57 UNREACHABLE(); |
| 56 } | 58 } |
| 57 | 59 |
| 58 } // namespace dart | 60 } // namespace dart |
| OLD | NEW |