blob: 2a272d305604a9025cf64a13711726e99fa97646 [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
Andreas Gampe70f5fd02018-10-24 19:58:37 -070019#include "class-alloc-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"
Mathieu Chartiereb8167a2014-05-07 15:43:14 -070023#include "handle_scope-inl.h"
Andreas Gampe8cf9cb32017-07-19 09:28:38 -070024#include "object-inl.h"
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080025#include "string.h"
26
27namespace art {
28namespace mirror {
29
Vladimir Markobdc93b42019-03-29 16:12:04 +000030ObjPtr<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) {
Mathieu Chartier28bd2e42016-10-04 13:54:57 -070035 ObjPtr<StackTraceElement> trace =
Vladimir Markoadbceb72018-05-29 14:34:14 +010036 ObjPtr<StackTraceElement>::DownCast(GetClassRoot<StackTraceElement>()->AllocObject(self));
Mathieu Chartier2cebb242015-04-21 16:50:40 -070037 if (LIKELY(trace != nullptr)) {
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +010038 if (Runtime::Current()->IsActiveTransaction()) {
Mathieu Chartier31e88222016-10-14 18:43:19 -070039 trace->Init<true>(declaring_class.Get(), method_name.Get(), file_name.Get(), line_number);
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +010040 } else {
Mathieu Chartier31e88222016-10-14 18:43:19 -070041 trace->Init<false>(declaring_class.Get(), method_name.Get(), file_name.Get(), line_number);
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +010042 }
Ian Rogersa436fde2013-08-27 23:34:06 -070043 }
Vladimir Markobdc93b42019-03-29 16:12:04 +000044 return trace;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080045}
46
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +010047template<bool kTransactionActive>
Mathieu Chartier31e88222016-10-14 18:43:19 -070048void StackTraceElement::Init(ObjPtr<String> declaring_class,
49 ObjPtr<String> method_name,
50 ObjPtr<String> file_name,
51 int32_t line_number) {
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +010052 SetFieldObject<kTransactionActive>(OFFSET_OF_OBJECT_MEMBER(StackTraceElement, declaring_class_),
Mathieu Chartier31e88222016-10-14 18:43:19 -070053 declaring_class);
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +010054 SetFieldObject<kTransactionActive>(OFFSET_OF_OBJECT_MEMBER(StackTraceElement, method_name_),
Mathieu Chartier31e88222016-10-14 18:43:19 -070055 method_name);
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +010056 SetFieldObject<kTransactionActive>(OFFSET_OF_OBJECT_MEMBER(StackTraceElement, file_name_),
Mathieu Chartier31e88222016-10-14 18:43:19 -070057 file_name);
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +010058 SetField32<kTransactionActive>(OFFSET_OF_OBJECT_MEMBER(StackTraceElement, line_number_),
Ian Rogersb0fa5dc2014-04-28 16:47:08 -070059 line_number);
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +010060}
61
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080062} // namespace mirror
63} // namespace art