objects.cc revision 50a4e4964bd66993e19768fc3af5b960653df8ed
150a4e4964bd66993e19768fc3af5b960653df8edAndreas Gampe/*
250a4e4964bd66993e19768fc3af5b960653df8edAndreas Gampe * Copyright (C) 2013 The Android Open Source Project
350a4e4964bd66993e19768fc3af5b960653df8edAndreas Gampe *
450a4e4964bd66993e19768fc3af5b960653df8edAndreas Gampe * Licensed under the Apache License, Version 2.0 (the "License");
550a4e4964bd66993e19768fc3af5b960653df8edAndreas Gampe * you may not use this file except in compliance with the License.
650a4e4964bd66993e19768fc3af5b960653df8edAndreas Gampe * You may obtain a copy of the License at
750a4e4964bd66993e19768fc3af5b960653df8edAndreas Gampe *
850a4e4964bd66993e19768fc3af5b960653df8edAndreas Gampe *      http://www.apache.org/licenses/LICENSE-2.0
950a4e4964bd66993e19768fc3af5b960653df8edAndreas Gampe *
1050a4e4964bd66993e19768fc3af5b960653df8edAndreas Gampe * Unless required by applicable law or agreed to in writing, software
1150a4e4964bd66993e19768fc3af5b960653df8edAndreas Gampe * distributed under the License is distributed on an "AS IS" BASIS,
1250a4e4964bd66993e19768fc3af5b960653df8edAndreas Gampe * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1350a4e4964bd66993e19768fc3af5b960653df8edAndreas Gampe * See the License for the specific language governing permissions and
1450a4e4964bd66993e19768fc3af5b960653df8edAndreas Gampe * limitations under the License.
1550a4e4964bd66993e19768fc3af5b960653df8edAndreas Gampe */
1650a4e4964bd66993e19768fc3af5b960653df8edAndreas Gampe
1750a4e4964bd66993e19768fc3af5b960653df8edAndreas Gampe#include "objects.h"
1850a4e4964bd66993e19768fc3af5b960653df8edAndreas Gampe
1950a4e4964bd66993e19768fc3af5b960653df8edAndreas Gampe#include <stdio.h>
2050a4e4964bd66993e19768fc3af5b960653df8edAndreas Gampe
2150a4e4964bd66993e19768fc3af5b960653df8edAndreas Gampe#include "base/macros.h"
2250a4e4964bd66993e19768fc3af5b960653df8edAndreas Gampe#include "jni.h"
2350a4e4964bd66993e19768fc3af5b960653df8edAndreas Gampe#include "openjdkjvmti/jvmti.h"
2450a4e4964bd66993e19768fc3af5b960653df8edAndreas Gampe#include "ScopedLocalRef.h"
2550a4e4964bd66993e19768fc3af5b960653df8edAndreas Gampe
2650a4e4964bd66993e19768fc3af5b960653df8edAndreas Gampe#include "ti-agent/common_helper.h"
2750a4e4964bd66993e19768fc3af5b960653df8edAndreas Gampe#include "ti-agent/common_load.h"
2850a4e4964bd66993e19768fc3af5b960653df8edAndreas Gampe
2950a4e4964bd66993e19768fc3af5b960653df8edAndreas Gampenamespace art {
3050a4e4964bd66993e19768fc3af5b960653df8edAndreas Gampenamespace Test920Objects {
3150a4e4964bd66993e19768fc3af5b960653df8edAndreas Gampe
3250a4e4964bd66993e19768fc3af5b960653df8edAndreas Gampeextern "C" JNIEXPORT jlong JNICALL Java_Main_getObjectSize(
3350a4e4964bd66993e19768fc3af5b960653df8edAndreas Gampe    JNIEnv* env ATTRIBUTE_UNUSED, jclass klass ATTRIBUTE_UNUSED, jobject object) {
3450a4e4964bd66993e19768fc3af5b960653df8edAndreas Gampe  jlong size;
3550a4e4964bd66993e19768fc3af5b960653df8edAndreas Gampe
3650a4e4964bd66993e19768fc3af5b960653df8edAndreas Gampe  jvmtiError result = jvmti_env->GetObjectSize(object, &size);
3750a4e4964bd66993e19768fc3af5b960653df8edAndreas Gampe  if (result != JVMTI_ERROR_NONE) {
3850a4e4964bd66993e19768fc3af5b960653df8edAndreas Gampe    char* err;
3950a4e4964bd66993e19768fc3af5b960653df8edAndreas Gampe    jvmti_env->GetErrorName(result, &err);
4050a4e4964bd66993e19768fc3af5b960653df8edAndreas Gampe    printf("Failure running GetObjectSize: %s\n", err);
4150a4e4964bd66993e19768fc3af5b960653df8edAndreas Gampe    jvmti_env->Deallocate(reinterpret_cast<unsigned char*>(err));
4250a4e4964bd66993e19768fc3af5b960653df8edAndreas Gampe    return -1;
4350a4e4964bd66993e19768fc3af5b960653df8edAndreas Gampe  }
4450a4e4964bd66993e19768fc3af5b960653df8edAndreas Gampe
4550a4e4964bd66993e19768fc3af5b960653df8edAndreas Gampe  return size;
4650a4e4964bd66993e19768fc3af5b960653df8edAndreas Gampe}
4750a4e4964bd66993e19768fc3af5b960653df8edAndreas Gampe
4850a4e4964bd66993e19768fc3af5b960653df8edAndreas Gampeextern "C" JNIEXPORT jint JNICALL Java_Main_getObjectHashCode(
4950a4e4964bd66993e19768fc3af5b960653df8edAndreas Gampe    JNIEnv* env ATTRIBUTE_UNUSED, jclass klass ATTRIBUTE_UNUSED, jobject object) {
5050a4e4964bd66993e19768fc3af5b960653df8edAndreas Gampe  jint hash;
5150a4e4964bd66993e19768fc3af5b960653df8edAndreas Gampe
5250a4e4964bd66993e19768fc3af5b960653df8edAndreas Gampe  jvmtiError result = jvmti_env->GetObjectHashCode(object, &hash);
5350a4e4964bd66993e19768fc3af5b960653df8edAndreas Gampe  if (result != JVMTI_ERROR_NONE) {
5450a4e4964bd66993e19768fc3af5b960653df8edAndreas Gampe    char* err;
5550a4e4964bd66993e19768fc3af5b960653df8edAndreas Gampe    jvmti_env->GetErrorName(result, &err);
5650a4e4964bd66993e19768fc3af5b960653df8edAndreas Gampe    printf("Failure running GetObjectHashCode: %s\n", err);
5750a4e4964bd66993e19768fc3af5b960653df8edAndreas Gampe    jvmti_env->Deallocate(reinterpret_cast<unsigned char*>(err));
5850a4e4964bd66993e19768fc3af5b960653df8edAndreas Gampe    return -1;
5950a4e4964bd66993e19768fc3af5b960653df8edAndreas Gampe  }
6050a4e4964bd66993e19768fc3af5b960653df8edAndreas Gampe
6150a4e4964bd66993e19768fc3af5b960653df8edAndreas Gampe  return hash;
6250a4e4964bd66993e19768fc3af5b960653df8edAndreas Gampe}
6350a4e4964bd66993e19768fc3af5b960653df8edAndreas Gampe
6450a4e4964bd66993e19768fc3af5b960653df8edAndreas Gampe// Don't do anything
6550a4e4964bd66993e19768fc3af5b960653df8edAndreas Gampejint OnLoad(JavaVM* vm,
6650a4e4964bd66993e19768fc3af5b960653df8edAndreas Gampe            char* options ATTRIBUTE_UNUSED,
6750a4e4964bd66993e19768fc3af5b960653df8edAndreas Gampe            void* reserved ATTRIBUTE_UNUSED) {
6850a4e4964bd66993e19768fc3af5b960653df8edAndreas Gampe  if (vm->GetEnv(reinterpret_cast<void**>(&jvmti_env), JVMTI_VERSION_1_0)) {
6950a4e4964bd66993e19768fc3af5b960653df8edAndreas Gampe    printf("Unable to get jvmti env!\n");
7050a4e4964bd66993e19768fc3af5b960653df8edAndreas Gampe    return 1;
7150a4e4964bd66993e19768fc3af5b960653df8edAndreas Gampe  }
7250a4e4964bd66993e19768fc3af5b960653df8edAndreas Gampe  SetAllCapabilities(jvmti_env);
7350a4e4964bd66993e19768fc3af5b960653df8edAndreas Gampe  return 0;
7450a4e4964bd66993e19768fc3af5b960653df8edAndreas Gampe}
7550a4e4964bd66993e19768fc3af5b960653df8edAndreas Gampe
7650a4e4964bd66993e19768fc3af5b960653df8edAndreas Gampe}  // namespace Test920Objects
7750a4e4964bd66993e19768fc3af5b960653df8edAndreas Gampe}  // namespace art
78