blob: cb8a86918f3982b45b3b23194b8943fcd33947ee [file] [log] [blame]
Elliott Hughes1240dad2011-09-09 16:24:50 -07001/*
2 * Copyright (C) 2008 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
Andreas Gampe277ccbd2014-11-03 21:36:10 -080017#include "java_lang_Throwable.h"
18
Elliott Hughes1240dad2011-09-09 16:24:50 -070019#include "jni_internal.h"
Ian Rogers53b8b092014-03-13 23:45:53 -070020#include "scoped_fast_native_object_access.h"
Ian Rogersaaa20802011-09-11 21:47:37 -070021#include "thread.h"
Elliott Hughes1240dad2011-09-09 16:24:50 -070022
Elliott Hughes1240dad2011-09-09 16:24:50 -070023namespace art {
24
Elliott Hughes0512f022012-03-15 22:10:52 -070025static jobject Throwable_nativeFillInStackTrace(JNIEnv* env, jclass) {
Ian Rogers53b8b092014-03-13 23:45:53 -070026 ScopedFastNativeObjectAccess soa(env);
Sebastien Hertzee1d79a2014-02-21 15:46:30 +010027 return soa.Self()->CreateInternalStackTrace<false>(soa);
Elliott Hughes1240dad2011-09-09 16:24:50 -070028}
29
Elliott Hughes0512f022012-03-15 22:10:52 -070030static jobjectArray Throwable_nativeGetStackTrace(JNIEnv* env, jclass, jobject javaStackState) {
Ian Rogers53b8b092014-03-13 23:45:53 -070031 if (javaStackState == nullptr) {
32 return nullptr;
Jesse Wilson32f85692011-11-22 11:00:41 -050033 }
Ian Rogers53b8b092014-03-13 23:45:53 -070034 ScopedFastNativeObjectAccess soa(env);
35 return Thread::InternalStackTraceToStackTraceElementArray(soa, javaStackState);
Elliott Hughes1240dad2011-09-09 16:24:50 -070036}
37
Elliott Hughes0512f022012-03-15 22:10:52 -070038static JNINativeMethod gMethods[] = {
Ian Rogers53b8b092014-03-13 23:45:53 -070039 NATIVE_METHOD(Throwable, nativeFillInStackTrace, "!()Ljava/lang/Object;"),
40 NATIVE_METHOD(Throwable, nativeGetStackTrace, "!(Ljava/lang/Object;)[Ljava/lang/StackTraceElement;"),
Elliott Hughes1240dad2011-09-09 16:24:50 -070041};
42
Elliott Hughes1240dad2011-09-09 16:24:50 -070043void register_java_lang_Throwable(JNIEnv* env) {
Elliott Hugheseac76672012-05-24 21:56:51 -070044 REGISTER_NATIVE_METHODS("java/lang/Throwable");
Elliott Hughes1240dad2011-09-09 16:24:50 -070045}
46
47} // namespace art