1 /*
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
17 /*
18 * java.lang.Throwable
19 */
20 #include "Dalvik.h"
21 #include "native/InternalNativePriv.h"
22
23
24 /*
25 * private static Object nativeFillInStackTrace()
26 */
Dalvik_java_lang_Throwable_nativeFillInStackTrace(const u4 * args,JValue * pResult)27 static void Dalvik_java_lang_Throwable_nativeFillInStackTrace(const u4* args,
28 JValue* pResult)
29 {
30 Object* stackState = NULL;
31
32 UNUSED_PARAMETER(args);
33
34 stackState = dvmFillInStackTrace(dvmThreadSelf());
35 RETURN_PTR(stackState);
36 }
37
38 /*
39 * private static StackTraceElement[] nativeGetStackTrace(Object stackState)
40 *
41 * The "stackState" argument must be the value returned by an earlier call to
42 * nativeFillInStackTrace().
43 */
Dalvik_java_lang_Throwable_nativeGetStackTrace(const u4 * args,JValue * pResult)44 static void Dalvik_java_lang_Throwable_nativeGetStackTrace(const u4* args,
45 JValue* pResult)
46 {
47 Object* stackState = (Object*) args[0];
48 ArrayObject* elements = NULL;
49
50 if (stackState == NULL) {
51 LOGW("getStackTrace() called but no trace available");
52 RETURN_PTR(NULL); /* could throw NPE; currently caller will do so */
53 }
54
55 elements = dvmGetStackTrace(stackState);
56 RETURN_PTR(elements);
57 }
58
59 const DalvikNativeMethod dvm_java_lang_Throwable[] = {
60 { "nativeFillInStackTrace", "()Ljava/lang/Object;",
61 Dalvik_java_lang_Throwable_nativeFillInStackTrace },
62 { "nativeGetStackTrace", "(Ljava/lang/Object;)[Ljava/lang/StackTraceElement;",
63 Dalvik_java_lang_Throwable_nativeGetStackTrace },
64 { NULL, NULL, NULL },
65 };
66