1 /*
2 * Copyright (C) 2022 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 "java_lang_StackStreamFactory.h"
18
19 #include "nativehelper/jni_macros.h"
20
21 #include "jni/jni_internal.h"
22 #include "native_util.h"
23 #include "scoped_fast_native_object_access-inl.h"
24 #include "thread.h"
25
26 namespace art {
27
StackStreamFactory_nativeGetStackAnchor(JNIEnv * env,jclass)28 static jobject StackStreamFactory_nativeGetStackAnchor(JNIEnv* env, jclass) {
29 ScopedFastNativeObjectAccess soa(env);
30 return soa.Self()->CreateInternalStackTrace(soa);
31 }
32
StackStreamFactory_nativeFetchStackFrameInfo(JNIEnv * env,jclass,jlong mode,jobject anchor,jint startLevel,jint batchSize,jint startBufferIndex,jobjectArray frameBuffer)33 static jint StackStreamFactory_nativeFetchStackFrameInfo(JNIEnv* env, jclass,
34 jlong mode, jobject anchor, jint startLevel, jint batchSize, jint startBufferIndex,
35 jobjectArray frameBuffer) {
36 if (anchor == nullptr) {
37 return startLevel;
38 }
39 ScopedFastNativeObjectAccess soa(env);
40 return Thread::InternalStackTraceToStackFrameInfoArray(soa, mode, anchor,
41 startLevel, batchSize, startBufferIndex, frameBuffer);
42 }
43
44 static JNINativeMethod gMethods[] = {
45 FAST_NATIVE_METHOD(StackStreamFactory, nativeGetStackAnchor, "()Ljava/lang/Object;"),
46 FAST_NATIVE_METHOD(StackStreamFactory, nativeFetchStackFrameInfo, "(JLjava/lang/Object;III[Ljava/lang/Object;)I"),
47 };
48
register_java_lang_StackStreamFactory(JNIEnv * env)49 void register_java_lang_StackStreamFactory(JNIEnv* env) {
50 REGISTER_NATIVE_METHODS("java/lang/StackStreamFactory");
51 }
52
53 } // namespace art
54