Andreas Gampe | 35bcf81 | 2017-01-13 16:24:17 -0800 | [diff] [blame] | 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 <inttypes.h> |
| 18 | |
Andreas Gampe | 027444b | 2017-03-31 12:49:07 -0700 | [diff] [blame] | 19 | #include "android-base/logging.h" |
Andreas Gampe | 35bcf81 | 2017-01-13 16:24:17 -0800 | [diff] [blame] | 20 | #include "android-base/stringprintf.h" |
Andreas Gampe | 027444b | 2017-03-31 12:49:07 -0700 | [diff] [blame] | 21 | |
Andreas Gampe | 35bcf81 | 2017-01-13 16:24:17 -0800 | [diff] [blame] | 22 | #include "jni.h" |
Andreas Gampe | 5e03a30 | 2017-03-13 13:10:00 -0700 | [diff] [blame] | 23 | #include "jvmti.h" |
Andreas Gampe | 35bcf81 | 2017-01-13 16:24:17 -0800 | [diff] [blame] | 24 | |
Andreas Gampe | 3f46c96 | 2017-03-30 10:26:59 -0700 | [diff] [blame] | 25 | // Test infrastructure |
| 26 | #include "jni_helper.h" |
| 27 | #include "jvmti_helper.h" |
| 28 | #include "test_env.h" |
Andreas Gampe | 027444b | 2017-03-31 12:49:07 -0700 | [diff] [blame] | 29 | #include "ti_macros.h" |
Andreas Gampe | 35bcf81 | 2017-01-13 16:24:17 -0800 | [diff] [blame] | 30 | |
| 31 | namespace art { |
| 32 | namespace Test926Timers { |
| 33 | |
Andreas Gampe | 4665167 | 2017-04-07 09:00:04 -0700 | [diff] [blame] | 34 | extern "C" JNIEXPORT jint JNICALL Java_art_Test927_getAvailableProcessors( |
Andreas Gampe | 35bcf81 | 2017-01-13 16:24:17 -0800 | [diff] [blame] | 35 | JNIEnv* env, jclass Main_klass ATTRIBUTE_UNUSED) { |
| 36 | jint count; |
| 37 | jvmtiError result = jvmti_env->GetAvailableProcessors(&count); |
Andreas Gampe | 3f46c96 | 2017-03-30 10:26:59 -0700 | [diff] [blame] | 38 | if (JvmtiErrorToException(env, jvmti_env, result)) { |
Andreas Gampe | 35bcf81 | 2017-01-13 16:24:17 -0800 | [diff] [blame] | 39 | return -1; |
| 40 | } |
| 41 | return count; |
| 42 | } |
| 43 | |
Andreas Gampe | 4665167 | 2017-04-07 09:00:04 -0700 | [diff] [blame] | 44 | extern "C" JNIEXPORT jlong JNICALL Java_art_Test927_getTime( |
Andreas Gampe | 35bcf81 | 2017-01-13 16:24:17 -0800 | [diff] [blame] | 45 | JNIEnv* env, jclass Main_klass ATTRIBUTE_UNUSED) { |
| 46 | jlong time; |
| 47 | jvmtiError result = jvmti_env->GetTime(&time); |
Andreas Gampe | 3f46c96 | 2017-03-30 10:26:59 -0700 | [diff] [blame] | 48 | if (JvmtiErrorToException(env, jvmti_env, result)) { |
Andreas Gampe | 35bcf81 | 2017-01-13 16:24:17 -0800 | [diff] [blame] | 49 | return -1; |
| 50 | } |
| 51 | return time; |
| 52 | } |
| 53 | |
Andreas Gampe | 4665167 | 2017-04-07 09:00:04 -0700 | [diff] [blame] | 54 | extern "C" JNIEXPORT jobjectArray JNICALL Java_art_Test927_getTimerInfo( |
Andreas Gampe | 35bcf81 | 2017-01-13 16:24:17 -0800 | [diff] [blame] | 55 | JNIEnv* env, jclass Main_klass ATTRIBUTE_UNUSED) { |
| 56 | jvmtiTimerInfo info; |
| 57 | jvmtiError result = jvmti_env->GetTimerInfo(&info); |
Andreas Gampe | 3f46c96 | 2017-03-30 10:26:59 -0700 | [diff] [blame] | 58 | if (JvmtiErrorToException(env, jvmti_env, result)) { |
Andreas Gampe | 35bcf81 | 2017-01-13 16:24:17 -0800 | [diff] [blame] | 59 | return nullptr; |
| 60 | } |
| 61 | |
| 62 | auto callback = [&](jint index) -> jobject { |
| 63 | switch (index) { |
| 64 | // Max value. |
| 65 | case 0: |
| 66 | return env->NewStringUTF(android::base::StringPrintf("%" PRId64, info.max_value).c_str()); |
| 67 | |
| 68 | // Skip forward. |
| 69 | case 1: |
| 70 | return env->NewStringUTF(info.may_skip_forward == JNI_TRUE ? "true" : "false"); |
| 71 | // Skip backward. |
| 72 | case 2: |
| 73 | return env->NewStringUTF(info.may_skip_forward == JNI_TRUE ? "true" : "false"); |
| 74 | |
| 75 | // The kind. |
| 76 | case 3: |
| 77 | return env->NewStringUTF( |
| 78 | android::base::StringPrintf("%d", static_cast<jint>(info.kind)).c_str()); |
| 79 | } |
| 80 | LOG(FATAL) << "Should not reach here"; |
| 81 | UNREACHABLE(); |
| 82 | }; |
| 83 | return CreateObjectArray(env, 4, "java/lang/Object", callback); |
| 84 | } |
| 85 | |
| 86 | } // namespace Test926Timers |
| 87 | } // namespace art |