• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2019 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 <jni.h>
18 #include <sstream>
19 #include <stdio.h>
20 
21 #include <android-base/logging.h>
22 #include <android-base/macros.h>
23 
24 #include "jni/java_vm_ext.h"
25 #include "runtime.h"
26 
27 namespace art {
28 
Java_Main_GetMethodId(JNIEnv * env,jclass k ATTRIBUTE_UNUSED,bool is_static,jclass target,jstring name,jstring sig)29 extern "C" JNIEXPORT jlong JNICALL Java_Main_GetMethodId(JNIEnv* env,
30                                                          jclass k ATTRIBUTE_UNUSED,
31                                                          bool is_static,
32                                                          jclass target,
33                                                          jstring name,
34                                                          jstring sig) {
35   auto get_id = is_static ? env->functions->GetStaticMethodID : env->functions->GetMethodID;
36   jboolean cpy;
37   const char* cname = env->GetStringUTFChars(name, &cpy);
38   const char* csig = env->GetStringUTFChars(sig, &cpy);
39   jlong res = static_cast<jlong>(reinterpret_cast<intptr_t>(get_id(env, target, cname, csig)));
40   env->ReleaseStringUTFChars(name, cname);
41   env->ReleaseStringUTFChars(sig, csig);
42   return res;
43 }
44 
Java_Main_GetJniType(JNIEnv * env,jclass k ATTRIBUTE_UNUSED)45 extern "C" JNIEXPORT jobject JNICALL Java_Main_GetJniType(JNIEnv* env, jclass k ATTRIBUTE_UNUSED) {
46   std::ostringstream oss;
47   oss << Runtime::Current()->GetJniIdType();
48   return env->NewStringUTF(oss.str().c_str());
49 }
50 
Java_Main_SetToPointerIds(JNIEnv * env ATTRIBUTE_UNUSED,jclass k ATTRIBUTE_UNUSED)51 extern "C" JNIEXPORT void JNICALL Java_Main_SetToPointerIds(JNIEnv* env ATTRIBUTE_UNUSED,
52                                                             jclass k ATTRIBUTE_UNUSED) {
53   Runtime::Current()->SetJniIdType(JniIdType::kPointer);
54 }
Java_Main_SetToIndexIds(JNIEnv * env ATTRIBUTE_UNUSED,jclass k ATTRIBUTE_UNUSED)55 extern "C" JNIEXPORT void JNICALL Java_Main_SetToIndexIds(JNIEnv* env ATTRIBUTE_UNUSED,
56                                                           jclass k ATTRIBUTE_UNUSED) {
57   Runtime::Current()->SetJniIdType(JniIdType::kIndices);
58 }
59 
60 }  // namespace art
61