jdk/src/share/demo/jvmti/java_crw_demo/java_crw_demo.h
author ohair
Tue, 25 May 2010 15:58:33 -0700
changeset 5506 202f599c92aa
parent 2 90ce3da70b43
child 10292 ed7db6a12c2a
permissions -rw-r--r--
6943119: Rebrand source copyright notices Reviewed-by: darcy, weijun
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     2
 * Copyright (c) 2003, 2004, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 * Redistribution and use in source and binary forms, with or without
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * modification, are permitted provided that the following conditions
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * are met:
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 *   - Redistributions of source code must retain the above copyright
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 *     notice, this list of conditions and the following disclaimer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 *   - Redistributions in binary form must reproduce the above copyright
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 *     notice, this list of conditions and the following disclaimer in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 *     documentation and/or other materials provided with the distribution.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    15
 *   - Neither the name of Oracle nor the names of its
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *     contributors may be used to endorse or promote products derived
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 *     from this software without specific prior written permission.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    21
 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
#ifndef JAVA_CRW_DEMO_H
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
#define JAVA_CRW_DEMO_H
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
#include <jni.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
#ifdef __cplusplus
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
extern "C" {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
/* This callback is used to notify the caller of a fatal error. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
typedef void (*FatalErrorHandler)(const char*message, const char*file, int line);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
/* This callback is used to return the method information for a class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 *   Since the information was already read here, it was useful to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 *   return it here, with no JVMTI phase restrictions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 *   If the class file does represent a "class" and it has methods, then
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 *   this callback will be called with the class number and pointers to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 *   the array of names, array of signatures, and the count of methods.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
typedef void (*MethodNumberRegister)(unsigned, const char**, const char**, int);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
/* Class file reader/writer interface. Basic input is a classfile image
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 *     and details about what to inject. The output is a new classfile image
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 *     that was allocated with malloc(), and should be freed by the caller.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
/* Names of external symbols to look for. These are the names that we
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 *   try and lookup in the shared library. On Windows 2000, the naming
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 *   convention is to prefix a "_" and suffix a "@N" where N is 4 times
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 *   the number or arguments supplied.It has 19 args, so 76 = 19*4.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 *   On Windows 2003, Linux, and Solaris, the first name will be
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 *   found, on Windows 2000 a second try should find the second name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
 *   WARNING: If You change the JavaCrwDemo typedef, you MUST change
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
 *            multiple things in this file, including this name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
#define JAVA_CRW_DEMO_SYMBOLS { "java_crw_demo", "_java_crw_demo@76" }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
/* Typedef needed for type casting in dynamic access situations. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
typedef void (JNICALL *JavaCrwDemo)(
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
         unsigned class_number,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
         const char *name,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
         const unsigned char *file_image,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
         long file_len,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
         int system_class,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
         char* tclass_name,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
         char* tclass_sig,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
         char* call_name,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
         char* call_sig,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
         char* return_name,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
         char* return_sig,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
         char* obj_init_name,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
         char* obj_init_sig,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
         char* newarray_name,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
         char* newarray_sig,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
         unsigned char **pnew_file_image,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
         long *pnew_file_len,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
         FatalErrorHandler fatal_error_handler,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
         MethodNumberRegister mnum_callback
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
/* Function export (should match typedef above) */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
JNIEXPORT void JNICALL java_crw_demo(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
         unsigned class_number, /* Caller assigned class number for class */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
         const char *name,      /* Internal class name, e.g. java/lang/Object */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
                                /*   (Do not use "java.lang.Object" format) */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
         const unsigned char
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
           *file_image,         /* Pointer to classfile image for this class */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
         long file_len,         /* Length of the classfile in bytes */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
         int system_class,      /* Set to 1 if this is a system class */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
                                /*   (prevents injections into empty */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
                                /*   <clinit>, finalize, and <init> methods) */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
         char* tclass_name,     /* Class that has methods we will call at */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
                                /*   the injection sites (tclass) */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
         char* tclass_sig,      /* Signature of tclass */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
                                /*  (Must be "L" + tclass_name + ";") */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
         char* call_name,       /* Method name in tclass to call at offset 0 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
                                /*   for every method */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
         char* call_sig,        /* Signature of this call_name method */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
                                /*  (Must be "(II)V") */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
         char* return_name,     /* Method name in tclass to call at all */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
                                /*  return opcodes in every method */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
         char* return_sig,      /* Signature of this return_name method */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
                                /*  (Must be "(II)V") */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
         char* obj_init_name,   /* Method name in tclass to call first thing */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
                                /*   when injecting java.lang.Object.<init> */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
         char* obj_init_sig,    /* Signature of this obj_init_name method */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
                                /*  (Must be "(Ljava/lang/Object;)V") */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
         char* newarray_name,   /* Method name in tclass to call after every */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
                                /*   newarray opcode in every method */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
         char* newarray_sig,    /* Signature of this method */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
                                /*  (Must be "(Ljava/lang/Object;II)V") */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
         unsigned char
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
           **pnew_file_image,   /* Returns a pointer to new classfile image */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
         long *pnew_file_len,   /* Returns the length of the new image */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
         FatalErrorHandler
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
           fatal_error_handler, /* Pointer to function to call on any */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
                                /*  fatal error. NULL sends error to stderr */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
         MethodNumberRegister
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
           mnum_callback        /* Pointer to function that gets called */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
                                /*   with all details on methods in this */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
                                /*   class. NULL means skip this call. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
           );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
/* External to read the class name out of a class file .
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
 *   WARNING: If You change the typedef, you MUST change
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
 *            multiple things in this file, including this name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
#define JAVA_CRW_DEMO_CLASSNAME_SYMBOLS \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
         { "java_crw_demo_classname", "_java_crw_demo_classname@12" }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
/* Typedef needed for type casting in dynamic access situations. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
typedef char * (JNICALL *JavaCrwDemoClassname)(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
         const unsigned char *file_image,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
         long file_len,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
         FatalErrorHandler fatal_error_handler);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
JNIEXPORT char * JNICALL java_crw_demo_classname(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
         const unsigned char *file_image,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
         long file_len,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
         FatalErrorHandler fatal_error_handler);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
#ifdef __cplusplus
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
} /* extern "C" */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
#endif /* __cplusplus */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
#endif