• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 <stdio.h>
18 
19 #include "android-base/macros.h"
20 
21 #include "jni.h"
22 #include "jvmti.h"
23 #include "scoped_local_ref.h"
24 
25 // Test infrastructure
26 #include "jni_helper.h"
27 #include "jvmti_helper.h"
28 #include "test_env.h"
29 
30 namespace art {
31 namespace Test991FieldTrace {
32 
Java_art_Test991_doNativeReadWrite(JNIEnv * env,jclass klass,jobject testclass)33 extern "C" JNIEXPORT void JNICALL Java_art_Test991_doNativeReadWrite(
34     JNIEnv* env, jclass klass, jobject testclass) {
35   CHECK(testclass != nullptr);
36   ScopedLocalRef<jclass> testclass_klass(env, env->GetObjectClass(testclass));
37   jmethodID notifyMethod = env->GetStaticMethodID(klass, "doPrintNativeNotification", "(I)V");
38   if (env->ExceptionCheck()) {
39     return;
40   }
41   jfieldID xyz_field = env->GetFieldID(testclass_klass.get(), "xyz", "I");
42   if (env->ExceptionCheck()) {
43     return;
44   }
45   jint val = env->GetIntField(testclass, xyz_field);
46   if (env->ExceptionCheck()) {
47     return;
48   }
49   env->CallStaticVoidMethod(klass, notifyMethod, val);
50   if (env->ExceptionCheck()) {
51     return;
52   }
53   val += 1;
54   env->SetIntField(testclass, xyz_field, val);
55 }
56 
57 }  // namespace Test991FieldTrace
58 }  // namespace art
59 
60