blob: ff353d893989da8bdc1e15bfcfa02636b82e8ff8 [file] [log] [blame]
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001/*
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
Hiroshi Yamauchi967a0ad2013-09-10 16:24:21 -070019#include "class-inl.h"
Andreas Gampe8cf9cb32017-07-19 09:28:38 -070020#include "class.h"
Vladimir Markoadbceb72018-05-29 14:34:14 +010021#include "class_root.h"
Ian Rogers1d54e732013-05-02 21:10:01 -070022#include "gc/accounting/card_table-inl.h"
Andreas Gampe508fdf32017-06-05 16:42:13 -070023#include "gc_root-inl.h"
Mathieu Chartiereb8167a2014-05-07 15:43:14 -070024#include "handle_scope-inl.h"
Andreas Gampe8cf9cb32017-07-19 09:28:38 -070025#include "object-inl.h"
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080026#include "string.h"
27
28namespace art {
29namespace mirror {
30
Mathieu Chartier31e88222016-10-14 18:43:19 -070031StackTraceElement* StackTraceElement::Alloc(Thread* self,
32 Handle<String> declaring_class,
33 Handle<String> method_name,
34 Handle<String> file_name,
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080035 int32_t line_number) {
Mathieu Chartier28bd2e42016-10-04 13:54:57 -070036 ObjPtr<StackTraceElement> trace =
Vladimir Markoadbceb72018-05-29 14:34:14 +010037 ObjPtr<StackTraceElement>::DownCast(GetClassRoot<StackTraceElement>()->AllocObject(self));
Mathieu Chartier2cebb242015-04-21 16:50:40 -070038 if (LIKELY(trace != nullptr)) {
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +010039 if (Runtime::Current()->IsActiveTransaction()) {
Mathieu Chartier31e88222016-10-14 18:43:19 -070040 trace->Init<true>(declaring_class.Get(), method_name.Get(), file_name.Get(), line_number);
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +010041 } else {
Mathieu Chartier31e88222016-10-14 18:43:19 -070042 trace->Init<false>(declaring_class.Get(), method_name.Get(), file_name.Get(), line_number);
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +010043 }
Ian Rogersa436fde2013-08-27 23:34:06 -070044 }
Mathieu Chartier28bd2e42016-10-04 13:54:57 -070045 return trace.Ptr();
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080046}
47
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +010048template<bool kTransactionActive>
Mathieu Chartier31e88222016-10-14 18:43:19 -070049void StackTraceElement::Init(ObjPtr<String> declaring_class,
50 ObjPtr<String> method_name,
51 ObjPtr<String> file_name,
52 int32_t line_number) {
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +010053 SetFieldObject<kTransactionActive>(OFFSET_OF_OBJECT_MEMBER(StackTraceElement, declaring_class_),
Mathieu Chartier31e88222016-10-14 18:43:19 -070054 declaring_class);
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +010055 SetFieldObject<kTransactionActive>(OFFSET_OF_OBJECT_MEMBER(StackTraceElement, method_name_),
Mathieu Chartier31e88222016-10-14 18:43:19 -070056 method_name);
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +010057 SetFieldObject<kTransactionActive>(OFFSET_OF_OBJECT_MEMBER(StackTraceElement, file_name_),
Mathieu Chartier31e88222016-10-14 18:43:19 -070058 file_name);
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +010059 SetField32<kTransactionActive>(OFFSET_OF_OBJECT_MEMBER(StackTraceElement, line_number_),
Ian Rogersb0fa5dc2014-04-28 16:47:08 -070060 line_number);
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +010061}
62
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080063} // namespace mirror
64} // namespace art