• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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-alloc-inl.h"
20 #include "class.h"
21 #include "class_root-inl.h"
22 #include "gc/accounting/card_table-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 
Alloc(Thread * self,Handle<String> declaring_class,Handle<String> method_name,Handle<String> file_name,int32_t line_number)30 ObjPtr<StackTraceElement> StackTraceElement::Alloc(Thread* self,
31                                                    Handle<String> declaring_class,
32                                                    Handle<String> method_name,
33                                                    Handle<String> file_name,
34                                                    int32_t line_number) {
35   ObjPtr<StackTraceElement> trace =
36       ObjPtr<StackTraceElement>::DownCast(GetClassRoot<StackTraceElement>()->AllocObject(self));
37   if (LIKELY(trace != nullptr)) {
38     if (Runtime::Current()->IsActiveTransaction()) {
39       trace->Init<true>(declaring_class.Get(), method_name.Get(), file_name.Get(), line_number);
40     } else {
41       trace->Init<false>(declaring_class.Get(), method_name.Get(), file_name.Get(), line_number);
42     }
43   }
44   return trace;
45 }
46 
47 template<bool kTransactionActive>
Init(ObjPtr<String> declaring_class,ObjPtr<String> method_name,ObjPtr<String> file_name,int32_t line_number)48 void StackTraceElement::Init(ObjPtr<String> declaring_class,
49                              ObjPtr<String> method_name,
50                              ObjPtr<String> file_name,
51                              int32_t line_number) {
52   SetFieldObject<kTransactionActive>(OFFSET_OF_OBJECT_MEMBER(StackTraceElement, declaring_class_),
53                                      declaring_class);
54   SetFieldObject<kTransactionActive>(OFFSET_OF_OBJECT_MEMBER(StackTraceElement, method_name_),
55                                      method_name);
56   SetFieldObject<kTransactionActive>(OFFSET_OF_OBJECT_MEMBER(StackTraceElement, file_name_),
57                                      file_name);
58   SetField32<kTransactionActive>(OFFSET_OF_OBJECT_MEMBER(StackTraceElement, line_number_),
59                                  line_number);
60 }
61 
62 }  // namespace mirror
63 }  // namespace art
64