blob: 0f488dc46a843c080d55dedec11b8a43f65aa204 [file] [log] [blame]
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001/*
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 Carlstromfc0e3212013-07-17 14:40:12 -070017#ifndef ART_RUNTIME_MIRROR_THROWABLE_H_
18#define ART_RUNTIME_MIRROR_THROWABLE_H_
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080019
Hiroshi Yamauchi94f7b492014-07-22 18:08:23 -070020#include "gc_root.h"
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080021#include "object.h"
Mathieu Chartier83c8ee02014-01-28 14:50:23 -080022#include "object_callbacks.h"
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080023#include "string.h"
24
25namespace art {
26
27struct ThrowableOffsets;
28
29namespace mirror {
30
31// C++ mirror of java.lang.Throwable
32class MANAGED Throwable : public Object {
33 public:
Mathieu Chartier90443472015-07-16 20:32:27 -070034 void SetDetailMessage(String* new_detail_message) SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogersb0fa5dc2014-04-28 16:47:08 -070035
Mathieu Chartier90443472015-07-16 20:32:27 -070036 String* GetDetailMessage() SHARED_REQUIRES(Locks::mutator_lock_) {
Ian Rogersb0fa5dc2014-04-28 16:47:08 -070037 return GetFieldObject<String>(OFFSET_OF_OBJECT_MEMBER(Throwable, detail_message_));
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080038 }
Ian Rogersb0fa5dc2014-04-28 16:47:08 -070039
Mathieu Chartier90443472015-07-16 20:32:27 -070040 std::string Dump() SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080041
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.
Mathieu Chartier90443472015-07-16 20:32:27 -070045 void SetCause(Throwable* cause) SHARED_REQUIRES(Locks::mutator_lock_);
46 void SetStackState(Object* state) SHARED_REQUIRES(Locks::mutator_lock_);
47 bool IsCheckedException() SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080048
Mathieu Chartier90443472015-07-16 20:32:27 -070049 static Class* GetJavaLangThrowable() SHARED_REQUIRES(Locks::mutator_lock_) {
Hiroshi Yamauchi94f7b492014-07-22 18:08:23 -070050 DCHECK(!java_lang_Throwable_.IsNull());
51 return java_lang_Throwable_.Read();
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080052 }
53
Mathieu Chartier90443472015-07-16 20:32:27 -070054 int32_t GetStackDepth() SHARED_REQUIRES(Locks::mutator_lock_);
Nicolas Geoffray7642cfc2015-02-26 10:56:09 +000055
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080056 static void SetClass(Class* java_lang_Throwable);
57 static void ResetClass();
Mathieu Chartierbb87e0f2015-04-03 11:21:55 -070058 static void VisitRoots(RootVisitor* visitor)
Mathieu Chartier90443472015-07-16 20:32:27 -070059 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080060
61 private:
Mathieu Chartier90443472015-07-16 20:32:27 -070062 Object* GetStackState() SHARED_REQUIRES(Locks::mutator_lock_) {
Ian Rogersb0fa5dc2014-04-28 16:47:08 -070063 return GetFieldObjectVolatile<Object>(OFFSET_OF_OBJECT_MEMBER(Throwable, stack_state_));
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080064 }
Mathieu Chartier90443472015-07-16 20:32:27 -070065 Object* GetStackTrace() SHARED_REQUIRES(Locks::mutator_lock_) {
Ian Rogersc45b8b52014-05-03 01:39:59 -070066 return GetFieldObjectVolatile<Object>(OFFSET_OF_OBJECT_MEMBER(Throwable, stack_trace_));
67 }
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080068
69 // Field order required by test "ValidateFieldOrderOfJavaCppUnionClasses".
Ian Rogersef7d42f2014-01-06 12:55:46 -080070 HeapReference<Throwable> cause_;
71 HeapReference<String> detail_message_;
72 HeapReference<Object> stack_state_; // Note this is Java volatile:
73 HeapReference<Object> stack_trace_;
74 HeapReference<Object> suppressed_exceptions_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080075
Hiroshi Yamauchi94f7b492014-07-22 18:08:23 -070076 static GcRoot<Class> java_lang_Throwable_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080077
78 friend struct art::ThrowableOffsets; // for verifying offset information
79 DISALLOW_IMPLICIT_CONSTRUCTORS(Throwable);
80};
81
82} // namespace mirror
83} // namespace art
84
Brian Carlstromfc0e3212013-07-17 14:40:12 -070085#endif // ART_RUNTIME_MIRROR_THROWABLE_H_