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 
17 #ifndef ART_RUNTIME_MIRROR_THROWABLE_H_
18 #define ART_RUNTIME_MIRROR_THROWABLE_H_
19 
20 #include "gc_root.h"
21 #include "object.h"
22 
23 namespace art {
24 
25 class RootVisitor;
26 struct ThrowableOffsets;
27 
28 namespace mirror {
29 
30 class String;
31 
32 // C++ mirror of java.lang.Throwable
33 class MANAGED Throwable : public Object {
34  public:
35   void SetDetailMessage(ObjPtr<String> new_detail_message) REQUIRES_SHARED(Locks::mutator_lock_);
36 
37   String* GetDetailMessage() REQUIRES_SHARED(Locks::mutator_lock_);
38 
39   std::string Dump() REQUIRES_SHARED(Locks::mutator_lock_);
40 
41   // This is a runtime version of initCause, you shouldn't use it if initCause may have been
42   // overridden. Also it asserts rather than throwing exceptions. Currently this is only used
43   // in cases like the verifier where the checks cannot fail and initCause isn't overridden.
44   void SetCause(ObjPtr<Throwable> cause) REQUIRES_SHARED(Locks::mutator_lock_);
45   void SetStackState(ObjPtr<Object> state) REQUIRES_SHARED(Locks::mutator_lock_);
46   bool IsCheckedException() REQUIRES_SHARED(Locks::mutator_lock_);
47 
GetJavaLangThrowable()48   static Class* GetJavaLangThrowable() REQUIRES_SHARED(Locks::mutator_lock_) {
49     DCHECK(!java_lang_Throwable_.IsNull());
50     return java_lang_Throwable_.Read();
51   }
52 
53   int32_t GetStackDepth() REQUIRES_SHARED(Locks::mutator_lock_);
54 
55   static void SetClass(ObjPtr<Class> java_lang_Throwable);
56   static void ResetClass();
57   static void VisitRoots(RootVisitor* visitor)
58       REQUIRES_SHARED(Locks::mutator_lock_);
59 
60  private:
61   Object* GetStackState() REQUIRES_SHARED(Locks::mutator_lock_);
62   Object* GetStackTrace() REQUIRES_SHARED(Locks::mutator_lock_);
63 
64   // Field order required by test "ValidateFieldOrderOfJavaCppUnionClasses".
65   HeapReference<Object> backtrace_;  // Note this is Java volatile:
66   HeapReference<Throwable> cause_;
67   HeapReference<String> detail_message_;
68   HeapReference<Object> stack_trace_;
69   HeapReference<Object> suppressed_exceptions_;
70 
71   static GcRoot<Class> java_lang_Throwable_;
72 
73   friend struct art::ThrowableOffsets;  // for verifying offset information
74   DISALLOW_IMPLICIT_CONSTRUCTORS(Throwable);
75 };
76 
77 }  // namespace mirror
78 }  // namespace art
79 
80 #endif  // ART_RUNTIME_MIRROR_THROWABLE_H_
81