blob: 9eaac719cd1ddb851d38331d56a4c1636789d5e8 [file] [log] [blame]
Andreas Gampe35bcf812017-01-13 16:24:17 -08001/*
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 Gampe027444b2017-03-31 12:49:07 -070019#include "android-base/logging.h"
Andreas Gampe35bcf812017-01-13 16:24:17 -080020#include "android-base/stringprintf.h"
Andreas Gampe027444b2017-03-31 12:49:07 -070021
Andreas Gampe35bcf812017-01-13 16:24:17 -080022#include "jni.h"
Andreas Gampe5e03a302017-03-13 13:10:00 -070023#include "jvmti.h"
Andreas Gampe35bcf812017-01-13 16:24:17 -080024
Andreas Gampe3f46c962017-03-30 10:26:59 -070025// Test infrastructure
26#include "jni_helper.h"
27#include "jvmti_helper.h"
28#include "test_env.h"
Andreas Gampe027444b2017-03-31 12:49:07 -070029#include "ti_macros.h"
Andreas Gampe35bcf812017-01-13 16:24:17 -080030
31namespace art {
32namespace Test926Timers {
33
Andreas Gampe46651672017-04-07 09:00:04 -070034extern "C" JNIEXPORT jint JNICALL Java_art_Test927_getAvailableProcessors(
Andreas Gampe35bcf812017-01-13 16:24:17 -080035 JNIEnv* env, jclass Main_klass ATTRIBUTE_UNUSED) {
36 jint count;
37 jvmtiError result = jvmti_env->GetAvailableProcessors(&count);
Andreas Gampe3f46c962017-03-30 10:26:59 -070038 if (JvmtiErrorToException(env, jvmti_env, result)) {
Andreas Gampe35bcf812017-01-13 16:24:17 -080039 return -1;
40 }
41 return count;
42}
43
Andreas Gampe46651672017-04-07 09:00:04 -070044extern "C" JNIEXPORT jlong JNICALL Java_art_Test927_getTime(
Andreas Gampe35bcf812017-01-13 16:24:17 -080045 JNIEnv* env, jclass Main_klass ATTRIBUTE_UNUSED) {
46 jlong time;
47 jvmtiError result = jvmti_env->GetTime(&time);
Andreas Gampe3f46c962017-03-30 10:26:59 -070048 if (JvmtiErrorToException(env, jvmti_env, result)) {
Andreas Gampe35bcf812017-01-13 16:24:17 -080049 return -1;
50 }
51 return time;
52}
53
Andreas Gampe46651672017-04-07 09:00:04 -070054extern "C" JNIEXPORT jobjectArray JNICALL Java_art_Test927_getTimerInfo(
Andreas Gampe35bcf812017-01-13 16:24:17 -080055 JNIEnv* env, jclass Main_klass ATTRIBUTE_UNUSED) {
56 jvmtiTimerInfo info;
57 jvmtiError result = jvmti_env->GetTimerInfo(&info);
Andreas Gampe3f46c962017-03-30 10:26:59 -070058 if (JvmtiErrorToException(env, jvmti_env, result)) {
Andreas Gampe35bcf812017-01-13 16:24:17 -080059 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