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 #include "stack_trace_element.h"
     18 
     19 #include "class-inl.h"
     20 #include "class.h"
     21 #include "gc/accounting/card_table-inl.h"
     22 #include "gc_root-inl.h"
     23 #include "handle_scope-inl.h"
     24 #include "object-inl.h"
     25 #include "string.h"
     26 
     27 namespace art {
     28 namespace mirror {
     29 
     30 GcRoot<Class> StackTraceElement::java_lang_StackTraceElement_;
     31 
     32 void StackTraceElement::SetClass(ObjPtr<Class> java_lang_StackTraceElement) {
     33   CHECK(java_lang_StackTraceElement_.IsNull());
     34   CHECK(java_lang_StackTraceElement != nullptr);
     35   java_lang_StackTraceElement_ = GcRoot<Class>(java_lang_StackTraceElement);
     36 }
     37 
     38 void StackTraceElement::ResetClass() {
     39   CHECK(!java_lang_StackTraceElement_.IsNull());
     40   java_lang_StackTraceElement_ = GcRoot<Class>(nullptr);
     41 }
     42 
     43 StackTraceElement* StackTraceElement::Alloc(Thread* self,
     44                                             Handle<String> declaring_class,
     45                                             Handle<String> method_name,
     46                                             Handle<String> file_name,
     47                                             int32_t line_number) {
     48   ObjPtr<StackTraceElement> trace =
     49       ObjPtr<StackTraceElement>::DownCast(GetStackTraceElement()->AllocObject(self));
     50   if (LIKELY(trace != nullptr)) {
     51     if (Runtime::Current()->IsActiveTransaction()) {
     52       trace->Init<true>(declaring_class.Get(), method_name.Get(), file_name.Get(), line_number);
     53     } else {
     54       trace->Init<false>(declaring_class.Get(), method_name.Get(), file_name.Get(), line_number);
     55     }
     56   }
     57   return trace.Ptr();
     58 }
     59 
     60 template<bool kTransactionActive>
     61 void StackTraceElement::Init(ObjPtr<String> declaring_class,
     62                              ObjPtr<String> method_name,
     63                              ObjPtr<String> file_name,
     64                              int32_t line_number) {
     65   SetFieldObject<kTransactionActive>(OFFSET_OF_OBJECT_MEMBER(StackTraceElement, declaring_class_),
     66                                      declaring_class);
     67   SetFieldObject<kTransactionActive>(OFFSET_OF_OBJECT_MEMBER(StackTraceElement, method_name_),
     68                                      method_name);
     69   SetFieldObject<kTransactionActive>(OFFSET_OF_OBJECT_MEMBER(StackTraceElement, file_name_),
     70                                      file_name);
     71   SetField32<kTransactionActive>(OFFSET_OF_OBJECT_MEMBER(StackTraceElement, line_number_),
     72                                  line_number);
     73 }
     74 
     75 void StackTraceElement::VisitRoots(RootVisitor* visitor) {
     76   java_lang_StackTraceElement_.VisitRootIfNonNull(visitor, RootInfo(kRootStickyClass));
     77 }
     78 
     79 
     80 }  // namespace mirror
     81 }  // namespace art
     82