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