/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* Copyright 2003 Wily Technology, Inc.
*/
#ifndef _JPLISAGENT_H_
#define _JPLISAGENT_H_
#include <jni.h>
#include <jvmti.h>
#ifdef __cplusplus
extern "C" {
#endif
/*
* The JPLISAgent manages the initialization all of the Java programming language Agents.
* It also supports the native method bridge between the JPLIS and the JVMTI.
* It maintains a single JVMTI Env that all JPL agents share.
* It parses command line requests and creates individual Java agents.
*/
/*
* Forward definitions
*/
struct _JPLISAgent;
/* constants for class names and methods names and such
these all must stay in sync with Java code & interfaces
*/
#define JPLIS_INSTRUMENTIMPL_PREMAININVOKER_METHODSIGNATURE "(Ljava/lang/String;Ljava/lang/String;)V"
#define JPLIS_INSTRUMENTIMPL_AGENTMAININVOKER_METHODSIGNATURE "(Ljava/lang/String;Ljava/lang/String;)V"
/*
* Error messages
*/
/*
* Our initialization errors
*/
typedef enum {
struct _JPLISEnvironment {
};
struct _JPLISAgent {
jmethodID mPremainCaller; /* method on the InstrumentationImpl that does the premain stuff (cached to save lots of lookups) */
jmethodID mAgentmainCaller; /* method on the InstrumentationImpl for agents loaded via attach mechanism */
jboolean mNativeMethodPrefixAdded; /* indicates if can_set_native_method_prefix capability has been added */
};
/*
* JVMTI event handlers
*/
/* VMInit event handler. Installed during OnLoad, then removed during VMInit. */
extern void JNICALL
/* ClassFileLoadHook event handler. Installed during VMInit, then left in place forever. */
extern void JNICALL
const char* name,
const unsigned char* class_data,
unsigned char** new_class_data);
/*
* Main entry points for the JPLIS JVMTI agent code
*/
/* looks up the environment instance. returns null if there isn't one */
extern JPLISEnvironment *
/* Creates a new JPLIS agent.
* Returns error if the agent cannot be created and initialized.
* The JPLISAgent* pointed to by agent_ptr is set to the new broker,
* or NULL if an error has occurred.
*/
extern JPLISInitializationError
/* Adds can_redefine_classes capability */
extern void
/* Add the can_set_native_method_prefix capability */
extern void
/* Add the can_maintain_original_method_order capability (for testing) */
extern void
/* Our JPLIS agent is paralleled by a Java InstrumentationImpl instance.
* This routine uses JNI to create and initialized the Java instance.
* Returns true if it succeeds, false otherwise.
*/
extern jboolean
JPLISAgent * agent);
/* during OnLoad phase (command line parsing)
* record the parameters of -javaagent
*/
extern JPLISInitializationError
const char * agentClass,
const char * optionsString );
/* Swaps the start phase event handlers out and the live phase event handlers in.
* Also used in attach to enabled live phase event handlers.
* Returns true if it succeeds, false otherwise.
*/
extern jboolean
/* Loads the Java agent according to the already processed command line. For each,
* loads the Java agent class, then calls the premain method.
* Returns true if all Java agent classes are loaded and all premain methods complete with no exceptions,
* false otherwise.
*/
extern jboolean
const char * classname,
const char * optionsString,
/* during VMInit processing
* this is how the invocation engine (callback wrapper) tells us to start up all the javaagents
*/
extern jboolean
/* on an ongoing basis,
* this is how the invocation engine (callback wrapper) tells us to process a class file
*/
extern void
const char* name,
const unsigned char* class_data,
unsigned char** new_class_data,
/* on an ongoing basis,
* Return the environment with the retransformation capability.
* Create it if it doesn't exist.
*/
extern jvmtiEnv *
/* on an ongoing basis,
* these are implementations of the Instrumentation services.
* Most are simple covers for JVMTI access services. These are the guts of the InstrumentationImpl
* native methods.
*/
extern jboolean
extern jboolean
extern void
extern void
extern void
extern jobjectArray
extern jobjectArray
extern jlong
extern void
appendToClassLoaderSearch(JNIEnv * jnienv, JPLISAgent * agent, jstring jarFile, jboolean isBootLoader);
extern void
/*
* A set of macros for insulating the JLI method callers from
* JVMTI_ERROR_WRONG_PHASE return codes.
*/
/* for a JLI method where "blob" is executed before simply returning */
if ((ret) == JVMTI_ERROR_WRONG_PHASE) { \
blob; \
return; \
}
/* for a JLI method where simply returning is benign */
if ((ret) == JVMTI_ERROR_WRONG_PHASE) { \
return; \
}
/* for a JLI method where returning zero (0) is benign */
if ((ret) == JVMTI_ERROR_WRONG_PHASE) { \
return 0; \
}
/* for a JLI method where returning one (1) is benign */
if ((ret) == JVMTI_ERROR_WRONG_PHASE) { \
return 1; \
}
/* for a case where a specific "blob" must be returned */
if ((ret) == JVMTI_ERROR_WRONG_PHASE) { \
return (blob); \
}
/* for a JLI method where returning false is benign */
if ((ret) == JVMTI_ERROR_WRONG_PHASE) { \
return (jboolean) 0; \
}
#ifdef __cplusplus
} /* extern "C" */
#endif /* __cplusplus */
#endif