jdk/src/java.instrument/share/native/libinstrument/InstrumentationImplNativeMethods.c
author alanb
Thu, 04 May 2017 07:26:55 +0000
changeset 45004 ea3137042a61
parent 33653 c1ee09fe3274
permissions -rw-r--r--
8178380: Module system implementation refresh (5/2017) Reviewed-by: mchung, alanb, sspitsyn Contributed-by: alan.bateman@oracle.com, mandy.chung@oracle.com, chris.hegarty@oracle.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
33653
c1ee09fe3274 8136556: Add the ability to perform static builds of MacOSX x64 binaries
bobv
parents: 25859
diff changeset
     2
 * Copyright (c) 2003, 2015, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1090
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1090
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1090
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1090
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1090
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
#include    <jni.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
#include    "JPLISAgent.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
#include    "JPLISAssert.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
#include    "Utilities.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
#include    "JavaExceptions.h"
1090
c5805b1672a6 6732421: Removed old javavm and Classic VM files from the jdk7 sources
ohair
parents: 2
diff changeset
    32
#include    "FileSystemSupport.h"   /* For uintptr_t */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
#include    "sun_instrument_InstrumentationImpl.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * Copyright 2003 Wily Technology, Inc.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * This module contains the native method implementations to back the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * sun.instrument.InstrumentationImpl class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * The bridge between Java and native code is built by storing a native
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * pointer to the JPLISAgent data structure in a 64 bit scalar field
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * in the InstrumentationImpl instance which is passed to each method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * Native methods
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
/*
33653
c1ee09fe3274 8136556: Add the ability to perform static builds of MacOSX x64 binaries
bobv
parents: 25859
diff changeset
    53
 * Declare library specific JNI_Onload entry if static build
c1ee09fe3274 8136556: Add the ability to perform static builds of MacOSX x64 binaries
bobv
parents: 25859
diff changeset
    54
 */
c1ee09fe3274 8136556: Add the ability to perform static builds of MacOSX x64 binaries
bobv
parents: 25859
diff changeset
    55
DEF_STATIC_JNI_OnLoad
c1ee09fe3274 8136556: Add the ability to perform static builds of MacOSX x64 binaries
bobv
parents: 25859
diff changeset
    56
c1ee09fe3274 8136556: Add the ability to perform static builds of MacOSX x64 binaries
bobv
parents: 25859
diff changeset
    57
/*
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 * Class:     sun_instrument_InstrumentationImpl
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 * Method:    isModifiableClass0
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 * Signature: (Ljava/lang/Class;)Z
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
JNIEXPORT jboolean JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
Java_sun_instrument_InstrumentationImpl_isModifiableClass0
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
  (JNIEnv * jnienv, jobject implThis, jlong agent, jclass clazz) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    return isModifiableClass(jnienv, (JPLISAgent*)(intptr_t)agent, clazz);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
 * Class:     sun_instrument_InstrumentationImpl
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
 * Method:    isRetransformClassesSupported0
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
 * Signature: ()Z
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
JNIEXPORT jboolean JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
Java_sun_instrument_InstrumentationImpl_isRetransformClassesSupported0
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
  (JNIEnv * jnienv, jobject implThis, jlong agent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    return isRetransformClassesSupported(jnienv, (JPLISAgent*)(intptr_t)agent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
 * Class:     sun_instrument_InstrumentationImpl
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
 * Method:    setHasRetransformableTransformers
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
 * Signature: (Z)V
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
JNIEXPORT void JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
Java_sun_instrument_InstrumentationImpl_setHasRetransformableTransformers
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
  (JNIEnv * jnienv, jobject implThis, jlong agent, jboolean has) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    setHasRetransformableTransformers(jnienv, (JPLISAgent*)(intptr_t)agent, has);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
 * Class:     sun_instrument_InstrumentationImpl
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
 * Method:    retransformClasses0
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
 * Signature: ([Ljava/lang/Class;)V
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
JNIEXPORT void JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
Java_sun_instrument_InstrumentationImpl_retransformClasses0
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
  (JNIEnv * jnienv, jobject implThis, jlong agent, jobjectArray classes) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    retransformClasses(jnienv, (JPLISAgent*)(intptr_t)agent, classes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
 * Class:     sun_instrument_InstrumentationImpl
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
 * Method:    redefineClasses0
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
 * Signature: ([Ljava/lang/instrument/ClassDefinition;)V
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
JNIEXPORT void JNICALL Java_sun_instrument_InstrumentationImpl_redefineClasses0
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
  (JNIEnv * jnienv, jobject implThis, jlong agent, jobjectArray classDefinitions) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
    redefineClasses(jnienv, (JPLISAgent*)(intptr_t)agent, classDefinitions);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
 * Class:     sun_instrument_InstrumentationImpl
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
 * Method:    getAllLoadedClasses0
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
 * Signature: ()[Ljava/lang/Class;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
JNIEXPORT jobjectArray JNICALL Java_sun_instrument_InstrumentationImpl_getAllLoadedClasses0
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
  (JNIEnv * jnienv, jobject implThis, jlong agent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
    return getAllLoadedClasses(jnienv, (JPLISAgent*)(intptr_t)agent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
 * Class:     sun_instrument_InstrumentationImpl
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
 * Method:    getInitiatedClasses0
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
 * Signature: (Ljava/lang/ClassLoader;)[Ljava/lang/Class;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
JNIEXPORT jobjectArray JNICALL Java_sun_instrument_InstrumentationImpl_getInitiatedClasses0
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
  (JNIEnv * jnienv, jobject implThis, jlong agent, jobject classLoader) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
    return getInitiatedClasses(jnienv, (JPLISAgent*)(intptr_t)agent, classLoader);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
 * Class:     sun_instrument_InstrumentationImpl
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
 * Method:    getObjectSize0
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
 * Signature: (Ljava/lang/Object;)J
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
JNIEXPORT jlong JNICALL Java_sun_instrument_InstrumentationImpl_getObjectSize0
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
  (JNIEnv * jnienv, jobject implThis, jlong agent, jobject objectToSize) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
    return getObjectSize(jnienv, (JPLISAgent*)(intptr_t)agent, objectToSize);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
 * Class:     sun_instrument_InstrumentationImpl
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
 * Method:    appendToClassLoaderSearch0
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
 * Signature: (Ljava/lang/String;Z)V
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
JNIEXPORT void JNICALL Java_sun_instrument_InstrumentationImpl_appendToClassLoaderSearch0
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
  (JNIEnv * jnienv, jobject implThis, jlong agent, jstring jarFile, jboolean isBootLoader) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
    appendToClassLoaderSearch(jnienv, (JPLISAgent*)(intptr_t)agent, jarFile, isBootLoader);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
 * Class:     sun_instrument_InstrumentationImpl
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
 * Method:    setNativeMethodPrefixes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
 * Signature: ([Ljava/lang/String;Z)V
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
JNIEXPORT void JNICALL Java_sun_instrument_InstrumentationImpl_setNativeMethodPrefixes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
  (JNIEnv * jnienv, jobject implThis, jlong agent, jobjectArray prefixArray, jboolean isRetransformable) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
    setNativeMethodPrefixes(jnienv, (JPLISAgent*)(intptr_t)agent, prefixArray, isRetransformable);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
}
45004
ea3137042a61 8178380: Module system implementation refresh (5/2017)
alanb
parents: 33653
diff changeset
   162
ea3137042a61 8178380: Module system implementation refresh (5/2017)
alanb
parents: 33653
diff changeset
   163
ea3137042a61 8178380: Module system implementation refresh (5/2017)
alanb
parents: 33653
diff changeset
   164
/*
ea3137042a61 8178380: Module system implementation refresh (5/2017)
alanb
parents: 33653
diff changeset
   165
 * Class:     sun_instrument_InstrumentationImpl
ea3137042a61 8178380: Module system implementation refresh (5/2017)
alanb
parents: 33653
diff changeset
   166
 * Method:    loadAgent0
ea3137042a61 8178380: Module system implementation refresh (5/2017)
alanb
parents: 33653
diff changeset
   167
 */
ea3137042a61 8178380: Module system implementation refresh (5/2017)
alanb
parents: 33653
diff changeset
   168
JNIEXPORT void JNICALL Java_sun_instrument_InstrumentationImpl_loadAgent0
ea3137042a61 8178380: Module system implementation refresh (5/2017)
alanb
parents: 33653
diff changeset
   169
   (JNIEnv* env, jclass clazz, jstring jarfile)
ea3137042a61 8178380: Module system implementation refresh (5/2017)
alanb
parents: 33653
diff changeset
   170
{
ea3137042a61 8178380: Module system implementation refresh (5/2017)
alanb
parents: 33653
diff changeset
   171
    extern jint loadAgent(JNIEnv* env, jstring path);
ea3137042a61 8178380: Module system implementation refresh (5/2017)
alanb
parents: 33653
diff changeset
   172
    if (loadAgent(env, jarfile) != JNI_OK) {
ea3137042a61 8178380: Module system implementation refresh (5/2017)
alanb
parents: 33653
diff changeset
   173
        if (!(*env)->ExceptionCheck(env)) {
ea3137042a61 8178380: Module system implementation refresh (5/2017)
alanb
parents: 33653
diff changeset
   174
            createAndThrowInternalError(env);
ea3137042a61 8178380: Module system implementation refresh (5/2017)
alanb
parents: 33653
diff changeset
   175
        }
ea3137042a61 8178380: Module system implementation refresh (5/2017)
alanb
parents: 33653
diff changeset
   176
    }
ea3137042a61 8178380: Module system implementation refresh (5/2017)
alanb
parents: 33653
diff changeset
   177
}
ea3137042a61 8178380: Module system implementation refresh (5/2017)
alanb
parents: 33653
diff changeset
   178