blob: cf54ad69a93894f3c913f536fd38f23cf0cd22f3 [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
20#include "object.h"
Mathieu Chartier83c8ee02014-01-28 14:50:23 -080021#include "object_callbacks.h"
Hiroshi Yamauchi4f1ebc22014-06-25 14:30:41 -070022#include "read_barrier.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:
Ian Rogersb0fa5dc2014-04-28 16:47:08 -070034 void SetDetailMessage(String* new_detail_message) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
35
Ian Rogersef7d42f2014-01-06 12:55:46 -080036 String* GetDetailMessage() SHARED_LOCKS_REQUIRED(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
Ian Rogersef7d42f2014-01-06 12:55:46 -080040 std::string Dump() SHARED_LOCKS_REQUIRED(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.
45 void SetCause(Throwable* cause) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogersc45b8b52014-05-03 01:39:59 -070046 void SetStackState(Object* state) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogersef7d42f2014-01-06 12:55:46 -080047 bool IsCheckedException() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080048
Hiroshi Yamauchi4f1ebc22014-06-25 14:30:41 -070049 static Class* GetJavaLangThrowable() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080050 DCHECK(java_lang_Throwable_ != NULL);
Hiroshi Yamauchi4f1ebc22014-06-25 14:30:41 -070051 return ReadBarrier::BarrierForRoot<mirror::Class, kWithReadBarrier>(
52 &java_lang_Throwable_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080053 }
54
55 static void SetClass(Class* java_lang_Throwable);
56 static void ResetClass();
Mathieu Chartier83c8ee02014-01-28 14:50:23 -080057 static void VisitRoots(RootCallback* callback, void* arg)
Mathieu Chartierc528dba2013-11-26 12:00:11 -080058 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080059
60 private:
Ian Rogersef7d42f2014-01-06 12:55:46 -080061 Object* GetStackState() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogersb0fa5dc2014-04-28 16:47:08 -070062 return GetFieldObjectVolatile<Object>(OFFSET_OF_OBJECT_MEMBER(Throwable, stack_state_));
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080063 }
Ian Rogersc45b8b52014-05-03 01:39:59 -070064 Object* GetStackTrace() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
65 return GetFieldObjectVolatile<Object>(OFFSET_OF_OBJECT_MEMBER(Throwable, stack_trace_));
66 }
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080067
68 // Field order required by test "ValidateFieldOrderOfJavaCppUnionClasses".
Ian Rogersef7d42f2014-01-06 12:55:46 -080069 HeapReference<Throwable> cause_;
70 HeapReference<String> detail_message_;
71 HeapReference<Object> stack_state_; // Note this is Java volatile:
72 HeapReference<Object> stack_trace_;
73 HeapReference<Object> suppressed_exceptions_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080074
75 static Class* java_lang_Throwable_;
76
77 friend struct art::ThrowableOffsets; // for verifying offset information
78 DISALLOW_IMPLICIT_CONSTRUCTORS(Throwable);
79};
80
81} // namespace mirror
82} // namespace art
83
Brian Carlstromfc0e3212013-07-17 14:40:12 -070084#endif // ART_RUNTIME_MIRROR_THROWABLE_H_