jdk/src/share/demo/jvmti/index.html
author ohair
Fri, 14 Jan 2011 14:04:54 -0800
changeset 8018 79ce40b4ab5e
parent 4808 37f605425f74
child 12056 1f93da3840f7
permissions -rw-r--r--
6950375: Remove msvcrt.dll from the Windows JRE bundles Reviewed-by: prr
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
<html>
90ce3da70b43 Initial load
duke
parents:
diff changeset
     2
<head> <title>JVM TI Demonstration Code</title> </head>
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
<h1>JVM TI Demonstration Code</h1>
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
The 
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
Java<sup><font size=-2>TM</font></sup> Virtual Machine Tools Interface (JVM TI)
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
is a native tool interface provided in JDK 5.0 and newer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
Native libraries that use JVM TI and are loaded into the 
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
Java Virtual Machine
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
via the -agentlib, -agentpath, or -Xrun (deprecated) interfaces, are
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
called Agents.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
<A HREF="http://java.sun.com/j2se/latest/docs/guide/jvmti">JVM TI</A>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
was designed to work with the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
Java Native Interface 
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
(<A HREF="http://java.sun.com/j2se/latest/docs/guide/jni">JNI</A>),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
and eventually displace the 
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
Java Virtual Machine Debugging Interface 
90ce3da70b43 Initial load
duke
parents:
diff changeset
    21
(<A HREF="http://java.sun.com/j2se/1.5.0/docs/guide/jpda/jvmdi-spec.html">JVMDI</A>)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
and the 
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
Java Virtual Machine Profiling Interface 
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
(<A HREF="http://java.sun.com/j2se/1.5.0/docs/guide/jvmpi/index.html">JVMPI</A>).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
We have created a set of demonstration agents that should
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
help show many of the features and abilities of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
interface. This list of demonstration agents will change over time.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
They are provided as educational tools and as starting
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
points for Java tool development.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
These agents are built with every JDK build and some basic testing is performed
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
on a regular basis, but no extensive testbases currently
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
exist for these agents.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
Every JDK installation should include all the pre-built binaries and sources for
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
all these agents, just look in the demo/jvmti directory of your JDK.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
<h2>Using or Running These Agents</h2>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
Using these agents will require the VM to locate the shared library file
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
before any actual Java code is run.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
The JDK installation should contain all the agent libraries in 
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
the ${JAVA_HOME}/demo/jvmti/<i>agent-name</i>/lib directories.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
The Solaris 64bit version would be contained in the sparcv9 or amd64
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
subdirectory.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
If 'java' complains that it can't find the library,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
you may need to add the directory containing the library into the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
LD_LIBRARY_PATH environment variable (Unix), or the PATH environment
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
variable (Windows).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
This is system and platform specific.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
If you are using 64bit Solaris (e.g. 'java -d64'), 
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
you should use LD_LIBRARY_PATH64.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
Some agents such as hprof (heap/cpu profiler) and jdwp (debugger backend)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
are located inside the primary JDK directories and will always be found
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
in those locations.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
The agents that instrument classfiles 
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
(i.e. BCI, usually through the java_crw_demo library) 
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
such as hprof, heapTracker, mtrace, and minst, 
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
also need to have the Java classes they use available in the bootclasspath.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
The one used by hprof is already in the bootclasspath, and the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
other agents will make attempts at automatically adding their jar file
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
(e.g. heapTracker.jar, mtrace.jar, or minst.jar) to the bootclasspath
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
with AddToBootstrapClassLoaderSearch from JVM TI at startup
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
(see the agent_util code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
This is done by locating this jar file at 
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
${JAVA_HOME}/demo/jvmti/<i>agent-name</i>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
where JAVA_HOME is obtained by calling GetSystemProperty from JVM TI
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
with "java.home".
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
We recognize that this is not ideal, but felt that as just demonstration
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
code it was acceptable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
Ideally the agent could find out the actual directory it came from and
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
locate the jar file relative to that location. 
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
Our demonstration agents currently do not do this.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
If you choose to modify or change these agents, the above information
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
is important in making everything is found.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
It is recommended that you change the name of the agent when you
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
modify it to avoid conflicts with the existing demo agents.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
Or better yet, go to http://jdk.dev.java.net and submit your
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
changes to the agent as an RFE to the JDK.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
<h2> Demonstration Agents Available </h2>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
<ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
<li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
<A HREF="versionCheck">versionCheck</A>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
<br>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
This is a extremely small agent that does nothing but check the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
version string supplied in the jvmti.h file, with the version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
number supplied by the VM at runtime.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
<li>
4808
37f605425f74 6580131: 3/4 CompiledMethodLoad events don't produce the expected extra notifications to describe inlining
dcubed
parents: 2
diff changeset
   103
<A HREF="compiledMethodLoad">compiledMethodLoad</A>
37f605425f74 6580131: 3/4 CompiledMethodLoad events don't produce the expected extra notifications to describe inlining
dcubed
parents: 2
diff changeset
   104
<br>
37f605425f74 6580131: 3/4 CompiledMethodLoad events don't produce the expected extra notifications to describe inlining
dcubed
parents: 2
diff changeset
   105
This is a small agent that traces CompiledMethodLoad events along
37f605425f74 6580131: 3/4 CompiledMethodLoad events don't produce the expected extra notifications to describe inlining
dcubed
parents: 2
diff changeset
   106
with the HotSpot specific compile_info parameter.
37f605425f74 6580131: 3/4 CompiledMethodLoad events don't produce the expected extra notifications to describe inlining
dcubed
parents: 2
diff changeset
   107
</li>
37f605425f74 6580131: 3/4 CompiledMethodLoad events don't produce the expected extra notifications to describe inlining
dcubed
parents: 2
diff changeset
   108
37f605425f74 6580131: 3/4 CompiledMethodLoad events don't produce the expected extra notifications to describe inlining
dcubed
parents: 2
diff changeset
   109
<li>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
<A HREF="mtrace">mtrace</A>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
<br>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
This is a small agent that does method tracing.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
It uses Bytecode Instrumentation (BCI) via the java_crw_demo library.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
<li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
<A HREF="minst">minst</A>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
<br>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
This is an even smaller agent that does just method entry tracing.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
It also uses Bytecode Instrumentation (BCI) via the java_crw_demo library,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
but the instrumentation code is pure Java (no Java native methods used).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
NOTE: Be sure to check out java.lang.instrument for a way to avoid
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
native code agents completely.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
<li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
<A HREF="gctest">gctest</A>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
<br>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
This is a small agent that does garbage collection counting.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
<li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
<A HREF="heapViewer">heapViewer</A>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
<br>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
This is a small agent that does some basic heap inspections.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
<li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
<A HREF="heapTracker">heapTracker</A>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
<br>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
This is a small agent that does BCI to capture object creation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
and track them.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
It uses Bytecode Instrumentation (BCI) via the java_crw_demo library.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
<li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
<A HREF="waiters">waiters</A>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
<br>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
This is a small agent that gets information about threads
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
waiting on monitors.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
<li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
<A HREF="hprof">hprof</A>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
<br>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
This is a large agent that does heap and cpu profiling.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
This demo agent is actually built into the 
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
Java Runtime Environment (JRE).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
It uses Bytecode Instrumentation (BCI) via the java_crw_demo library.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
<br>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
<b>Note:</b> hprof is NOT a small or simple agent, the other smaller demos
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
should be looked at first.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
</ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
<h2>Agent Support</h2>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
<ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
<li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
<A HREF="java_crw_demo">java_crw_demo</A>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
<br>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
This is a demo C library that does class file to class file
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
transformations or BCI (Bytecode Instrumentation).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
It is used by several of the above agents.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
</ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
<h2>Native Library Build Hints</h2>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
All libraries loaded into java are assumed to be MT-safe (Multi-thread safe).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
This means that multiple threads could be executing the code at the same
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
time, and static or global data may need to be placed in critical
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
sections. See the Raw Monitor interfaces for more information.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
All native libraries loaded into the 
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
Java Virtual Machine,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
including Agent libraries,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
need to be compiled and built in a compatible way.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
Certain native compilation options or optimizations should be avoided,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
and some are required.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
More information on this options is available in the man pages for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
the various compilers.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
Some native compiler and linker options can create fatal or 
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
erroneous behavior when native agent libraries are operating
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
inside the Java Virtual Machine.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
It would take too many words to describe all the possible issues with all
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
the native compiler options, optimizations, and settings.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
Here are some recommendations on the basic compiler and linker options
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
we recommend:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
<ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
<h3> Solaris </h3>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
<li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
On Solaris, using the Sun Studio 11 C compiler,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
the typical compile and link command lines might look something like:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
<br>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
For 32bit SPARC:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
<br>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
<code><ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
cc -xO2 -mt -xregs=no%appl -xmemalign=4s -xarch=v8 -KPIC -c <i>*.c</i>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
<br>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
cc -mt -xarch=v8 -z defs -ztext -G -o <i>libXXX.so *.o</i> -lc
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
</code></ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
<br>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
For 64bit SPARC:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
<br>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
<code><ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
cc -xO2 -mt -xregs=no%appl -xarch=v9 -KPIC -c <i>*.c</i>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
<br>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
cc -mt -xarch=v9 -z defs -ztext -G -o <i>libXXX.so *.o</i> -lc
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
</code></ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
<br>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
For X86:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
<br>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
<code><ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
cc -xO2 -mt -xregs=no%frameptr -KPIC -c <i>*.c</i>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
<br>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
cc -mt -z defs -ztext -G -o <i>libXXX.so *.o</i> -lc
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
</code></ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
<br>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
For AMD64:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
<br>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
<code><ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
cc -xO2 -mt -xregs=no%frameptr -xarch=amd64 -KPIC -c <i>*.c</i>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
<br>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
cc -mt -xarch=amd64 -z defs -ztext -G -o <i>libXXX.so *.o</i> -lc
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
</code></ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
<br>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
<li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
Architecture/File Format: 
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
For SPARC 32bit use <code>-xarch=v8</code>, 
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
for SPARC 64bit use <code>-xarch=v9</code>, 
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
for X86 (32-bit) 
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
<i>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
leave the option off or use <code>-xarch=generic</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
</i>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
and for AMD64 (64bit) use <code>-xarch=amd64</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
with both C and C++.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
<br>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
This is to be specific as to the architecture and the file format
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
of the .o files (and ultimately of the .so). 
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
<li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
MT-Safe, Position Independent: Use <code>-KPIC -mt</code> 
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
with both C and C++.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
<li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
Register usage: For SPARC (both 32bit and 64bit) use 
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
<code>-xregs=no%appl</code> and for X86 and AMD64 use <code>-xregs=no%frameptr</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
with both C and C++.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
<li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
Alignment: For SPARC 32bit use -xmemalign=4s and for SPARC 64bit do NOT use <code>-xmemalign=4</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
with both C and C++.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
<li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
Dependencies: Use <code>ldd -r <i>LibraryName</i></code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
<br>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
After the shared library has been built, the utility
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
<code>ldd</code> can be used to verify that all dependent libraries 
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
have been satisfied, and all externs can be found.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
If <code>ldd</code> says anything is missing, it is very likely that the JVM will also
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
be unable to load this library.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
This usually means that you missed some <code>-l<i>name</i></code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
options when building the library, or perhaps forgot a <code>-R path</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
option that tells the library where to look for libraries at runtime.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
<h3> Linux </h3>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
<li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
On Linux, using the gcc version 3.2, 
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
the typical compile and link command lines might look something like:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
<br>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
For X86:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
<br>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
<code><ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
gcc -O2 -fPIC -pthread -DLINUX -c <i>*.c</i>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
<br>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
gcc -z defs -static-libgcc -shared -mimpure-text -o <i>libXXX.so *.o</i> -lc
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
</code></ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
<br>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
For AMD64:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
<br>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
<code><ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
gcc -O2 -fPIC -pthread -DLINUX -D_LP64=1 -c <i>*.c</i>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
<br>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
gcc -z defs -static-libgcc -shared -mimpure-text -o <i>libXXX.so *.o</i> -lc
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
</code></ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
<br>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
<li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
MT-Safe, Position Independent: 
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
Use <code>-fPIC -pthread</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
<li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
Agent Demo Code: Needs -DLINUX
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
<li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
Register Usage: Use <code>-fno-omit-frame-pointer</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
<br>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
It is important that these libraries have frame pointer register usage, see the above comments on the Solaris 
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
<code>-xregs=no%frameptr</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
option.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
<li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
Library: Use -static-libgcc -mimpure-text.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
<br>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
When building the shared library (-shared option), this option
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
allows for maximum portability of the library between different
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
flavors of Linux.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
The problem we have seen with Linux is that we cannot depend
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
on a compatible shared gcc library existing on all the versions of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
Linux we can run on.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
By doing this static link, the version script becomes more
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
important, making sure you don't expose any extern symbols
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
you didn't intend to.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
<li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
Dependencies: Use <code>ldd -r <i>LibraryName</i></code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
<br>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
Provides the same checking as Solaris (see above).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
<h3> Windows </h3>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
<li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
On Windows and using the Microsoft C++ Compiler Visual Studio .NET 2003,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
the typical compile and link command lines might look something like:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
<br>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
For X86:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
<br>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
<code><ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
cl /O1 /MD /D _STATIC_CPPLIB /c <i>*.c</i>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
<br>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
link /dll /opt:REF /out:<i>XXX.dll *.obj</i>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
</code></ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
<br>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
For AMD64:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
<br>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
<code><ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
cl /O1 /MD /D _STATIC_CPPLIB /c <i>*.c</i>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
<br>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
link /dll /opt:REF /out:<i>XXX.dll *.obj</i>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
</code></ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
<br>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
<li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
Library: Use <code>/opt:REF </code> when building the dll.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
<li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
MS DLL Runtime: Use the <code>/MD /D _STATIC_CPPLIB</code> option.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
<br>
8018
79ce40b4ab5e 6950375: Remove msvcrt.dll from the Windows JRE bundles
ohair
parents: 4808
diff changeset
   392
This causes your dll to become dependent on just MSVCR*.DLL.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
The option /D _STATIC_CPPLIB prevents you from becoming dependent on the
8018
79ce40b4ab5e 6950375: Remove msvcrt.dll from the Windows JRE bundles
ohair
parents: 4808
diff changeset
   394
C++ library MSVCP*.DLL.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
This is what we use in the JDK, but there are probably many combinations
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
that you could safely use, unfortunately there are many combinations
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
of runtimes that will not work. 
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
Check the Microsoft site on proper use of runtimes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
<li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
Dependencies: Use VC++ <code>dumpbin /exports</code> and the VC++ "Dependency Walker".
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
<br>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
Provides dependency information similar to <code>ldd</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
</ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
<h2>For More Information</h2>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
Remember, the complete source to all these agents is contained in the JDK
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
installations at demo/jvmti.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
For more detailed information on JVM TI, refer to 
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
<A HREF="http://java.sun.com/j2se/latest/docs/guide/jvmti">
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
http://java.sun.com/j2se/latest/docs/guide/jvmti.</A>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
 
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
More information on using JNI and building native libraries refer to:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
<A HREF="http://java.sun.com/j2se/latest/docs/guide/jni">
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
http://java.sun.com/j2se/latest/docs/guide/jni</A>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
Additional information can also be found by doing a search on "jvmti" at
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
<A HREF="http://java.sun.com/j2se">http://java.sun.com/j2se</A>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
Various technical articles are also available through this website.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
And don't forget the 
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
Java Tutorials at 
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
<A HREF="http://java.sun.com/docs/books/tutorial">http://java.sun.com/docs/books/tutorial</A>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
for getting a quick start on all the various interfaces.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
<h2>Comments and Feedback</h2>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
Comments regarding JVM TI or on any of these demonstrations should be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
sent through 
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
<A HREF="http://java.sun.com/mail">http://java.sun.com/mail/</A>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
</html>