Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 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.h" |
Hiroshi Yamauchi | 967a0ad | 2013-09-10 16:24:21 -0700 | [diff] [blame] | 20 | #include "class-inl.h" |
Ian Rogers | 1d54e73 | 2013-05-02 21:10:01 -0700 | [diff] [blame] | 21 | #include "gc/accounting/card_table-inl.h" |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 22 | #include "object-inl.h" |
Mathieu Chartier | c645f1d | 2014-03-06 18:11:53 -0800 | [diff] [blame] | 23 | #include "sirt_ref-inl.h" |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 24 | #include "string.h" |
| 25 | |
| 26 | namespace art { |
| 27 | namespace mirror { |
| 28 | |
| 29 | Class* StackTraceElement::java_lang_StackTraceElement_ = NULL; |
| 30 | |
| 31 | void StackTraceElement::SetClass(Class* java_lang_StackTraceElement) { |
| 32 | CHECK(java_lang_StackTraceElement_ == NULL); |
| 33 | CHECK(java_lang_StackTraceElement != NULL); |
| 34 | java_lang_StackTraceElement_ = java_lang_StackTraceElement; |
| 35 | } |
| 36 | |
| 37 | void StackTraceElement::ResetClass() { |
| 38 | CHECK(java_lang_StackTraceElement_ != NULL); |
| 39 | java_lang_StackTraceElement_ = NULL; |
| 40 | } |
| 41 | |
| 42 | StackTraceElement* StackTraceElement::Alloc(Thread* self, |
Mathieu Chartier | 590fee9 | 2013-09-13 13:46:47 -0700 | [diff] [blame] | 43 | SirtRef<String>& declaring_class, |
| 44 | SirtRef<String>& method_name, |
| 45 | SirtRef<String>& file_name, |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 46 | int32_t line_number) { |
| 47 | StackTraceElement* trace = |
| 48 | down_cast<StackTraceElement*>(GetStackTraceElement()->AllocObject(self)); |
Ian Rogers | a436fde | 2013-08-27 23:34:06 -0700 | [diff] [blame] | 49 | if (LIKELY(trace != NULL)) { |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 50 | if (Runtime::Current()->IsActiveTransaction()) { |
| 51 | trace->Init<true>(declaring_class, method_name, file_name, line_number); |
| 52 | } else { |
| 53 | trace->Init<false>(declaring_class, method_name, file_name, line_number); |
| 54 | } |
Ian Rogers | a436fde | 2013-08-27 23:34:06 -0700 | [diff] [blame] | 55 | } |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 56 | return trace; |
| 57 | } |
| 58 | |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 59 | template<bool kTransactionActive> |
| 60 | void StackTraceElement::Init(SirtRef<String>& declaring_class, SirtRef<String>& method_name, |
| 61 | SirtRef<String>& file_name, int32_t line_number) { |
| 62 | SetFieldObject<kTransactionActive>(OFFSET_OF_OBJECT_MEMBER(StackTraceElement, declaring_class_), |
Ian Rogers | b0fa5dc | 2014-04-28 16:47:08 -0700 | [diff] [blame^] | 63 | declaring_class.get()); |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 64 | SetFieldObject<kTransactionActive>(OFFSET_OF_OBJECT_MEMBER(StackTraceElement, method_name_), |
Ian Rogers | b0fa5dc | 2014-04-28 16:47:08 -0700 | [diff] [blame^] | 65 | method_name.get()); |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 66 | SetFieldObject<kTransactionActive>(OFFSET_OF_OBJECT_MEMBER(StackTraceElement, file_name_), |
Ian Rogers | b0fa5dc | 2014-04-28 16:47:08 -0700 | [diff] [blame^] | 67 | file_name.get()); |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 68 | SetField32<kTransactionActive>(OFFSET_OF_OBJECT_MEMBER(StackTraceElement, line_number_), |
Ian Rogers | b0fa5dc | 2014-04-28 16:47:08 -0700 | [diff] [blame^] | 69 | line_number); |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 70 | } |
| 71 | |
Mathieu Chartier | 83c8ee0 | 2014-01-28 14:50:23 -0800 | [diff] [blame] | 72 | void StackTraceElement::VisitRoots(RootCallback* callback, void* arg) { |
Mathieu Chartier | c528dba | 2013-11-26 12:00:11 -0800 | [diff] [blame] | 73 | if (java_lang_StackTraceElement_ != nullptr) { |
Mathieu Chartier | 815873e | 2014-02-13 18:02:13 -0800 | [diff] [blame] | 74 | callback(reinterpret_cast<mirror::Object**>(&java_lang_StackTraceElement_), arg, 0, |
| 75 | kRootStickyClass); |
Mathieu Chartier | c528dba | 2013-11-26 12:00:11 -0800 | [diff] [blame] | 76 | } |
| 77 | } |
| 78 | |
| 79 | |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 80 | } // namespace mirror |
| 81 | } // namespace art |