Home | History | Annotate | Download | only in 1914-get-local-instance
      1 /*
      2  * Copyright (C) 2017 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 <iostream>
     18 #include <pthread.h>
     19 #include <stdio.h>
     20 #include <vector>
     21 
     22 #include "android-base/logging.h"
     23 #include "jni.h"
     24 #include "scoped_local_ref.h"
     25 #include "scoped_primitive_array.h"
     26 
     27 #include "jvmti.h"
     28 
     29 // Test infrastructure
     30 #include "jvmti_helper.h"
     31 #include "test_env.h"
     32 
     33 namespace art {
     34 namespace Test1914LocalInstance {
     35 
     36 extern "C" JNIEXPORT void Java_art_Test1914_00024TargetClass_NativeInstanceMethod(
     37     JNIEnv* env, jobject thiz, jobject run) {
     38   ScopedLocalRef<jclass> runnable(env, env->FindClass("java/lang/Runnable"));
     39   if (env->ExceptionCheck()) { return; }
     40   jmethodID method = env->GetMethodID(runnable.get(), "run", "()V");
     41   if (env->ExceptionCheck()) { return; }
     42   env->CallVoidMethod(run, method);
     43   if (env->ExceptionCheck()) { return; }
     44   ScopedLocalRef<jclass> Test1914(env, env->FindClass("art/Test1914"));
     45   if (env->ExceptionCheck()) { return; }
     46   jmethodID report = env->GetStaticMethodID(Test1914.get(), "reportValue", "(Ljava/lang/Object;)V");
     47   if (env->ExceptionCheck()) { return; }
     48   env->CallStaticVoidMethod(Test1914.get(), report, thiz);
     49 }
     50 
     51 extern "C" JNIEXPORT void Java_art_Test1914_NativeStaticMethod(
     52     JNIEnv* env, jclass, jobject run) {
     53   ScopedLocalRef<jclass> runnable(env, env->FindClass("java/lang/Runnable"));
     54   if (env->ExceptionCheck()) { return; }
     55   jmethodID method = env->GetMethodID(runnable.get(), "run", "()V");
     56   if (env->ExceptionCheck()) { return; }
     57   env->CallVoidMethod(run, method);
     58   if (env->ExceptionCheck()) { return; }
     59   ScopedLocalRef<jclass> Test1914(env, env->FindClass("art/Test1914"));
     60   if (env->ExceptionCheck()) { return; }
     61   jmethodID report = env->GetStaticMethodID(Test1914.get(), "reportValue", "(Ljava/lang/Object;)V");
     62   if (env->ExceptionCheck()) { return; }
     63   env->CallStaticVoidMethod(Test1914.get(), report, nullptr);
     64 }
     65 
     66 }  // namespace Test1914LocalInstance
     67 }  // namespace art
     68 
     69