1 /*
   2  * Copyright (c) 2003, 2008, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 #include    <jni.h>
  27 
  28 #include    "JPLISAgent.h"
  29 #include    "JPLISAssert.h"
  30 #include    "Utilities.h"
  31 #include    "JavaExceptions.h"
  32 #include    "FileSystemSupport.h"   /* For uintptr_t */
  33 #include    "sun_instrument_InstrumentationImpl.h"
  34 
  35 /*
  36  * Copyright 2003 Wily Technology, Inc.
  37  */
  38 
  39 /**
  40  * This module contains the native method implementations to back the
  41  * sun.instrument.InstrumentationImpl class.
  42  * The bridge between Java and native code is built by storing a native
  43  * pointer to the JPLISAgent data structure in a 64 bit scalar field
  44  * in the InstrumentationImpl instance which is passed to each method.
  45  */
  46 
  47 
  48 /*
  49  * Native methods
  50  */
  51 
  52 /*
  53  * Class:     sun_instrument_InstrumentationImpl
  54  * Method:    isModifiableClass0
  55  * Signature: (Ljava/lang/Class;)Z
  56  */
  57 JNIEXPORT jboolean JNICALL
  58 Java_sun_instrument_InstrumentationImpl_isModifiableClass0
  59   (JNIEnv * jnienv, jobject implThis, jlong agent, jclass clazz) {
  60     return isModifiableClass(jnienv, (JPLISAgent*)(intptr_t)agent, clazz);
  61 }
  62 
  63 /*
  64  * Class:     sun_instrument_InstrumentationImpl
  65  * Method:    isRetransformClassesSupported0
  66  * Signature: ()Z
  67  */
  68 JNIEXPORT jboolean JNICALL
  69 Java_sun_instrument_InstrumentationImpl_isRetransformClassesSupported0
  70   (JNIEnv * jnienv, jobject implThis, jlong agent) {
  71     return isRetransformClassesSupported(jnienv, (JPLISAgent*)(intptr_t)agent);
  72 }
  73 
  74 /*
  75  * Class:     sun_instrument_InstrumentationImpl
  76  * Method:    setHasRetransformableTransformers
  77  * Signature: (Z)V
  78  */
  79 JNIEXPORT void JNICALL
  80 Java_sun_instrument_InstrumentationImpl_setHasRetransformableTransformers
  81   (JNIEnv * jnienv, jobject implThis, jlong agent, jboolean has) {
  82     setHasRetransformableTransformers(jnienv, (JPLISAgent*)(intptr_t)agent, has);
  83 }
  84 
  85 /*
  86  * Class:     sun_instrument_InstrumentationImpl
  87  * Method:    retransformClasses0
  88  * Signature: ([Ljava/lang/Class;)V
  89  */
  90 JNIEXPORT void JNICALL
  91 Java_sun_instrument_InstrumentationImpl_retransformClasses0
  92   (JNIEnv * jnienv, jobject implThis, jlong agent, jobjectArray classes) {
  93     retransformClasses(jnienv, (JPLISAgent*)(intptr_t)agent, classes);
  94 }
  95 
  96 /*
  97  * Class:     sun_instrument_InstrumentationImpl
  98  * Method:    redefineClasses0
  99  * Signature: ([Ljava/lang/instrument/ClassDefinition;)V
 100  */
 101 JNIEXPORT void JNICALL Java_sun_instrument_InstrumentationImpl_redefineClasses0
 102   (JNIEnv * jnienv, jobject implThis, jlong agent, jobjectArray classDefinitions) {
 103     redefineClasses(jnienv, (JPLISAgent*)(intptr_t)agent, classDefinitions);
 104 }
 105 
 106 /*
 107  * Class:     sun_instrument_InstrumentationImpl
 108  * Method:    getAllLoadedClasses0
 109  * Signature: ()[Ljava/lang/Class;
 110  */
 111 JNIEXPORT jobjectArray JNICALL Java_sun_instrument_InstrumentationImpl_getAllLoadedClasses0
 112   (JNIEnv * jnienv, jobject implThis, jlong agent) {
 113     return getAllLoadedClasses(jnienv, (JPLISAgent*)(intptr_t)agent);
 114 }
 115 
 116 /*
 117  * Class:     sun_instrument_InstrumentationImpl
 118  * Method:    getInitiatedClasses0
 119  * Signature: (Ljava/lang/ClassLoader;)[Ljava/lang/Class;
 120  */
 121 JNIEXPORT jobjectArray JNICALL Java_sun_instrument_InstrumentationImpl_getInitiatedClasses0
 122   (JNIEnv * jnienv, jobject implThis, jlong agent, jobject classLoader) {
 123     return getInitiatedClasses(jnienv, (JPLISAgent*)(intptr_t)agent, classLoader);
 124 }
 125 
 126 /*
 127  * Class:     sun_instrument_InstrumentationImpl
 128  * Method:    getObjectSize0
 129  * Signature: (Ljava/lang/Object;)J
 130  */
 131 JNIEXPORT jlong JNICALL Java_sun_instrument_InstrumentationImpl_getObjectSize0
 132   (JNIEnv * jnienv, jobject implThis, jlong agent, jobject objectToSize) {
 133     return getObjectSize(jnienv, (JPLISAgent*)(intptr_t)agent, objectToSize);
 134 }
 135 
 136 
 137 /*
 138  * Class:     sun_instrument_InstrumentationImpl
 139  * Method:    appendToClassLoaderSearch0
 140  * Signature: (Ljava/lang/String;Z)V
 141  */
 142 JNIEXPORT void JNICALL Java_sun_instrument_InstrumentationImpl_appendToClassLoaderSearch0
 143   (JNIEnv * jnienv, jobject implThis, jlong agent, jstring jarFile, jboolean isBootLoader) {
 144     appendToClassLoaderSearch(jnienv, (JPLISAgent*)(intptr_t)agent, jarFile, isBootLoader);
 145 }
 146 
 147 
 148 /*
 149  * Class:     sun_instrument_InstrumentationImpl
 150  * Method:    setNativeMethodPrefixes
 151  * Signature: ([Ljava/lang/String;Z)V
 152  */
 153 JNIEXPORT void JNICALL Java_sun_instrument_InstrumentationImpl_setNativeMethodPrefixes
 154   (JNIEnv * jnienv, jobject implThis, jlong agent, jobjectArray prefixArray, jboolean isRetransformable) {
 155     setNativeMethodPrefixes(jnienv, (JPLISAgent*)(intptr_t)agent, prefixArray, isRetransformable);
 156 }