Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2011 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
Brian Carlstrom | fc0e321 | 2013-07-17 14:40:12 -0700 | [diff] [blame] | 17 | #ifndef ART_RUNTIME_MIRROR_THROWABLE_H_ |
| 18 | #define ART_RUNTIME_MIRROR_THROWABLE_H_ |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 19 | |
Hiroshi Yamauchi | 94f7b49 | 2014-07-22 18:08:23 -0700 | [diff] [blame] | 20 | #include "gc_root.h" |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 21 | #include "object.h" |
Mathieu Chartier | 83c8ee0 | 2014-01-28 14:50:23 -0800 | [diff] [blame] | 22 | #include "object_callbacks.h" |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 23 | #include "string.h" |
| 24 | |
| 25 | namespace art { |
| 26 | |
| 27 | struct ThrowableOffsets; |
| 28 | |
| 29 | namespace mirror { |
| 30 | |
| 31 | // C++ mirror of java.lang.Throwable |
| 32 | class MANAGED Throwable : public Object { |
| 33 | public: |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame^] | 34 | void SetDetailMessage(String* new_detail_message) REQUIRES_SHARED(Locks::mutator_lock_); |
Ian Rogers | b0fa5dc | 2014-04-28 16:47:08 -0700 | [diff] [blame] | 35 | |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame^] | 36 | String* GetDetailMessage() REQUIRES_SHARED(Locks::mutator_lock_) { |
Ian Rogers | b0fa5dc | 2014-04-28 16:47:08 -0700 | [diff] [blame] | 37 | return GetFieldObject<String>(OFFSET_OF_OBJECT_MEMBER(Throwable, detail_message_)); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 38 | } |
Ian Rogers | b0fa5dc | 2014-04-28 16:47:08 -0700 | [diff] [blame] | 39 | |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame^] | 40 | std::string Dump() REQUIRES_SHARED(Locks::mutator_lock_); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 41 | |
| 42 | // This is a runtime version of initCause, you shouldn't use it if initCause may have been |
| 43 | // overridden. Also it asserts rather than throwing exceptions. Currently this is only used |
| 44 | // in cases like the verifier where the checks cannot fail and initCause isn't overridden. |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame^] | 45 | void SetCause(Throwable* cause) REQUIRES_SHARED(Locks::mutator_lock_); |
| 46 | void SetStackState(Object* state) REQUIRES_SHARED(Locks::mutator_lock_); |
| 47 | bool IsCheckedException() REQUIRES_SHARED(Locks::mutator_lock_); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 48 | |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame^] | 49 | static Class* GetJavaLangThrowable() REQUIRES_SHARED(Locks::mutator_lock_) { |
Hiroshi Yamauchi | 94f7b49 | 2014-07-22 18:08:23 -0700 | [diff] [blame] | 50 | DCHECK(!java_lang_Throwable_.IsNull()); |
| 51 | return java_lang_Throwable_.Read(); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 52 | } |
| 53 | |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame^] | 54 | int32_t GetStackDepth() REQUIRES_SHARED(Locks::mutator_lock_); |
Nicolas Geoffray | 7642cfc | 2015-02-26 10:56:09 +0000 | [diff] [blame] | 55 | |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 56 | static void SetClass(Class* java_lang_Throwable); |
| 57 | static void ResetClass(); |
Mathieu Chartier | bb87e0f | 2015-04-03 11:21:55 -0700 | [diff] [blame] | 58 | static void VisitRoots(RootVisitor* visitor) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame^] | 59 | REQUIRES_SHARED(Locks::mutator_lock_); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 60 | |
| 61 | private: |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame^] | 62 | Object* GetStackState() REQUIRES_SHARED(Locks::mutator_lock_) { |
Piotr Jastrzebski | c16a50f | 2015-05-07 09:41:00 +0100 | [diff] [blame] | 63 | return GetFieldObjectVolatile<Object>(OFFSET_OF_OBJECT_MEMBER(Throwable, backtrace_)); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 64 | } |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame^] | 65 | Object* GetStackTrace() REQUIRES_SHARED(Locks::mutator_lock_) { |
Przemyslaw Szczepaniak | 121b25e | 2015-11-20 11:24:33 +0000 | [diff] [blame] | 66 | return GetFieldObjectVolatile<Object>(OFFSET_OF_OBJECT_MEMBER(Throwable, backtrace_)); |
Ian Rogers | c45b8b5 | 2014-05-03 01:39:59 -0700 | [diff] [blame] | 67 | } |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 68 | |
| 69 | // Field order required by test "ValidateFieldOrderOfJavaCppUnionClasses". |
Piotr Jastrzebski | c16a50f | 2015-05-07 09:41:00 +0100 | [diff] [blame] | 70 | HeapReference<Object> backtrace_; // Note this is Java volatile: |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 71 | HeapReference<Throwable> cause_; |
| 72 | HeapReference<String> detail_message_; |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 73 | HeapReference<Object> stack_trace_; |
| 74 | HeapReference<Object> suppressed_exceptions_; |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 75 | |
Hiroshi Yamauchi | 94f7b49 | 2014-07-22 18:08:23 -0700 | [diff] [blame] | 76 | static GcRoot<Class> java_lang_Throwable_; |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 77 | |
| 78 | friend struct art::ThrowableOffsets; // for verifying offset information |
| 79 | DISALLOW_IMPLICIT_CONSTRUCTORS(Throwable); |
| 80 | }; |
| 81 | |
| 82 | } // namespace mirror |
| 83 | } // namespace art |
| 84 | |
Brian Carlstrom | fc0e321 | 2013-07-17 14:40:12 -0700 | [diff] [blame] | 85 | #endif // ART_RUNTIME_MIRROR_THROWABLE_H_ |