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 | |
| 19 | #include "android-base/stringprintf.h" |
| 20 | #include "base/logging.h" |
| 21 | #include "base/macros.h" |
| 22 | #include "jni.h" |
| 23 | #include "openjdkjvmti/jvmti.h" |
| 24 | |
| 25 | #include "ti-agent/common_helper.h" |
| 26 | #include "ti-agent/common_load.h" |
| 27 | |
| 28 | namespace art { |
| 29 | namespace Test926Timers { |
| 30 | |
| 31 | extern "C" JNIEXPORT jint JNICALL Java_Main_getAvailableProcessors( |
| 32 | JNIEnv* env, jclass Main_klass ATTRIBUTE_UNUSED) { |
| 33 | jint count; |
| 34 | jvmtiError result = jvmti_env->GetAvailableProcessors(&count); |
| 35 | if (JvmtiErrorToException(env, result)) { |
| 36 | return -1; |
| 37 | } |
| 38 | return count; |
| 39 | } |
| 40 | |
| 41 | extern "C" JNIEXPORT jlong JNICALL Java_Main_getTime( |
| 42 | JNIEnv* env, jclass Main_klass ATTRIBUTE_UNUSED) { |
| 43 | jlong time; |
| 44 | jvmtiError result = jvmti_env->GetTime(&time); |
| 45 | if (JvmtiErrorToException(env, result)) { |
| 46 | return -1; |
| 47 | } |
| 48 | return time; |
| 49 | } |
| 50 | |
| 51 | extern "C" JNIEXPORT jobjectArray JNICALL Java_Main_getTimerInfo( |
| 52 | JNIEnv* env, jclass Main_klass ATTRIBUTE_UNUSED) { |
| 53 | jvmtiTimerInfo info; |
| 54 | jvmtiError result = jvmti_env->GetTimerInfo(&info); |
| 55 | if (JvmtiErrorToException(env, result)) { |
| 56 | return nullptr; |
| 57 | } |
| 58 | |
| 59 | auto callback = [&](jint index) -> jobject { |
| 60 | switch (index) { |
| 61 | // Max value. |
| 62 | case 0: |
| 63 | return env->NewStringUTF(android::base::StringPrintf("%" PRId64, info.max_value).c_str()); |
| 64 | |
| 65 | // Skip forward. |
| 66 | case 1: |
| 67 | return env->NewStringUTF(info.may_skip_forward == JNI_TRUE ? "true" : "false"); |
| 68 | // Skip backward. |
| 69 | case 2: |
| 70 | return env->NewStringUTF(info.may_skip_forward == JNI_TRUE ? "true" : "false"); |
| 71 | |
| 72 | // The kind. |
| 73 | case 3: |
| 74 | return env->NewStringUTF( |
| 75 | android::base::StringPrintf("%d", static_cast<jint>(info.kind)).c_str()); |
| 76 | } |
| 77 | LOG(FATAL) << "Should not reach here"; |
| 78 | UNREACHABLE(); |
| 79 | }; |
| 80 | return CreateObjectArray(env, 4, "java/lang/Object", callback); |
| 81 | } |
| 82 | |
| 83 | } // namespace Test926Timers |
| 84 | } // namespace art |