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_STACK_TRACE_ELEMENT_H_ 18 #define ART_RUNTIME_MIRROR_STACK_TRACE_ELEMENT_H_ 19 20 #include "gc_root.h" 21 #include "object.h" 22 23 namespace art { 24 25 template<class T> class Handle; 26 struct StackTraceElementOffsets; 27 28 namespace mirror { 29 30 // C++ mirror of java.lang.StackTraceElement 31 class MANAGED StackTraceElement FINAL : public Object { 32 public: GetDeclaringClass()33 String* GetDeclaringClass() REQUIRES_SHARED(Locks::mutator_lock_) { 34 return GetFieldObject<String>(OFFSET_OF_OBJECT_MEMBER(StackTraceElement, declaring_class_)); 35 } 36 GetMethodName()37 String* GetMethodName() REQUIRES_SHARED(Locks::mutator_lock_) { 38 return GetFieldObject<String>(OFFSET_OF_OBJECT_MEMBER(StackTraceElement, method_name_)); 39 } 40 GetFileName()41 String* GetFileName() REQUIRES_SHARED(Locks::mutator_lock_) { 42 return GetFieldObject<String>(OFFSET_OF_OBJECT_MEMBER(StackTraceElement, file_name_)); 43 } 44 GetLineNumber()45 int32_t GetLineNumber() REQUIRES_SHARED(Locks::mutator_lock_) { 46 return GetField32(OFFSET_OF_OBJECT_MEMBER(StackTraceElement, line_number_)); 47 } 48 49 static StackTraceElement* Alloc(Thread* self, 50 Handle<String> declaring_class, 51 Handle<String> method_name, 52 Handle<String> file_name, 53 int32_t line_number) 54 REQUIRES_SHARED(Locks::mutator_lock_) REQUIRES(!Roles::uninterruptible_); 55 56 static void SetClass(ObjPtr<Class> java_lang_StackTraceElement); 57 static void ResetClass(); 58 static void VisitRoots(RootVisitor* visitor) 59 REQUIRES_SHARED(Locks::mutator_lock_); GetStackTraceElement()60 static Class* GetStackTraceElement() REQUIRES_SHARED(Locks::mutator_lock_) { 61 DCHECK(!java_lang_StackTraceElement_.IsNull()); 62 return java_lang_StackTraceElement_.Read(); 63 } 64 65 private: 66 // Field order required by test "ValidateFieldOrderOfJavaCppUnionClasses". 67 HeapReference<String> declaring_class_; 68 HeapReference<String> file_name_; 69 HeapReference<String> method_name_; 70 int32_t line_number_; 71 72 template<bool kTransactionActive> 73 void Init(ObjPtr<String> declaring_class, 74 ObjPtr<String> method_name, 75 ObjPtr<String> file_name, 76 int32_t line_number) 77 REQUIRES_SHARED(Locks::mutator_lock_); 78 79 static GcRoot<Class> java_lang_StackTraceElement_; 80 81 friend struct art::StackTraceElementOffsets; // for verifying offset information 82 DISALLOW_IMPLICIT_CONSTRUCTORS(StackTraceElement); 83 }; 84 85 } // namespace mirror 86 } // namespace art 87 88 #endif // ART_RUNTIME_MIRROR_STACK_TRACE_ELEMENT_H_ 89