blob: b901ca2d006c24a26e2bd0591823beb9d7629c97 [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"
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080022
23namespace art {
24
Andreas Gampe5d08fcc2017-06-05 17:56:46 -070025class RootVisitor;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080026struct ThrowableOffsets;
27
28namespace mirror {
29
Andreas Gampe5d08fcc2017-06-05 17:56:46 -070030class String;
31
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080032// C++ mirror of java.lang.Throwable
33class MANAGED Throwable : public Object {
34 public:
Mathieu Chartier31e88222016-10-14 18:43:19 -070035 void SetDetailMessage(ObjPtr<String> new_detail_message) REQUIRES_SHARED(Locks::mutator_lock_);
Ian Rogersb0fa5dc2014-04-28 16:47:08 -070036
Andreas Gampe5d08fcc2017-06-05 17:56:46 -070037 String* GetDetailMessage() REQUIRES_SHARED(Locks::mutator_lock_);
Ian Rogersb0fa5dc2014-04-28 16:47:08 -070038
Andreas Gampebdf7f1c2016-08-30 16:38:47 -070039 std::string Dump() REQUIRES_SHARED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080040
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.
Mathieu Chartier31e88222016-10-14 18:43:19 -070044 void SetCause(ObjPtr<Throwable> cause) REQUIRES_SHARED(Locks::mutator_lock_);
45 void SetStackState(ObjPtr<Object> state) REQUIRES_SHARED(Locks::mutator_lock_);
Andreas Gampebdf7f1c2016-08-30 16:38:47 -070046 bool IsCheckedException() REQUIRES_SHARED(Locks::mutator_lock_);
Orion Hodsonba46c6d2018-02-27 12:42:11 +000047 bool IsError() REQUIRES_SHARED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080048
Andreas Gampebdf7f1c2016-08-30 16:38:47 -070049 static Class* GetJavaLangThrowable() REQUIRES_SHARED(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
Andreas Gampebdf7f1c2016-08-30 16:38:47 -070054 int32_t GetStackDepth() REQUIRES_SHARED(Locks::mutator_lock_);
Nicolas Geoffray7642cfc2015-02-26 10:56:09 +000055
Mathieu Chartier31e88222016-10-14 18:43:19 -070056 static void SetClass(ObjPtr<Class> java_lang_Throwable);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080057 static void ResetClass();
Mathieu Chartierbb87e0f2015-04-03 11:21:55 -070058 static void VisitRoots(RootVisitor* visitor)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -070059 REQUIRES_SHARED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080060
61 private:
Andreas Gampe5d08fcc2017-06-05 17:56:46 -070062 Object* GetStackState() REQUIRES_SHARED(Locks::mutator_lock_);
63 Object* GetStackTrace() REQUIRES_SHARED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080064
65 // Field order required by test "ValidateFieldOrderOfJavaCppUnionClasses".
Piotr Jastrzebskic16a50f2015-05-07 09:41:00 +010066 HeapReference<Object> backtrace_; // Note this is Java volatile:
Ian Rogersef7d42f2014-01-06 12:55:46 -080067 HeapReference<Throwable> cause_;
68 HeapReference<String> detail_message_;
Ian Rogersef7d42f2014-01-06 12:55:46 -080069 HeapReference<Object> stack_trace_;
70 HeapReference<Object> suppressed_exceptions_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080071
Hiroshi Yamauchi94f7b492014-07-22 18:08:23 -070072 static GcRoot<Class> java_lang_Throwable_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080073
74 friend struct art::ThrowableOffsets; // for verifying offset information
75 DISALLOW_IMPLICIT_CONSTRUCTORS(Throwable);
76};
77
78} // namespace mirror
79} // namespace art
80
Brian Carlstromfc0e3212013-07-17 14:40:12 -070081#endif // ART_RUNTIME_MIRROR_THROWABLE_H_