You are viewing a plain text version of this content. The canonical link for it is here.
Posted to kato-commits@incubator.apache.org by sp...@apache.org on 2009/09/07 09:20:59 UTC
svn commit: r812050 [1/2] - in /incubator/kato/trunk/org.apache.kato: ./
kato.cjvmti/ kato.native/ kato.native/.settings/
kato.native/kato.native.cjvmti/ kato.native/kato.native.cjvmti/.settings/
kato.native/kato.native.cjvmti/linux-x86/ kato.native/ka...
Author: spoole
Date: Mon Sep 7 09:20:52 2009
New Revision: 812050
URL: http://svn.apache.org/viewvc?rev=812050&view=rev
Log:
Check in of Paul Sobecks cjvmti code - native and java. Made to build under main kato maven project as sub module. kato-9 kato-10
Added:
incubator/kato/trunk/org.apache.kato/kato.native/
incubator/kato/trunk/org.apache.kato/kato.native/.classpath (with props)
incubator/kato/trunk/org.apache.kato/kato.native/.project (with props)
incubator/kato/trunk/org.apache.kato/kato.native/.settings/
incubator/kato/trunk/org.apache.kato/kato.native/.settings/org.eclipse.jdt.core.prefs (with props)
incubator/kato/trunk/org.apache.kato/kato.native/.settings/org.maven.ide.eclipse.prefs (with props)
incubator/kato/trunk/org.apache.kato/kato.native/kato.native.cjvmti/
incubator/kato/trunk/org.apache.kato/kato.native/kato.native.cjvmti/.classpath (with props)
incubator/kato/trunk/org.apache.kato/kato.native/kato.native.cjvmti/.project (with props)
incubator/kato/trunk/org.apache.kato/kato.native/kato.native.cjvmti/.settings/
incubator/kato/trunk/org.apache.kato/kato.native/kato.native.cjvmti/.settings/org.eclipse.jdt.core.prefs (with props)
incubator/kato/trunk/org.apache.kato/kato.native/kato.native.cjvmti/.settings/org.maven.ide.eclipse.prefs (with props)
incubator/kato/trunk/org.apache.kato/kato.native/kato.native.cjvmti/linux-x86/
incubator/kato/trunk/org.apache.kato/kato.native/kato.native.cjvmti/linux-x86/pom.xml (with props)
incubator/kato/trunk/org.apache.kato/kato.native/kato.native.cjvmti/linux-x86/target/
incubator/kato/trunk/org.apache.kato/kato.native/kato.native.cjvmti/linux-x86/target/libcjvmti.so (with props)
incubator/kato/trunk/org.apache.kato/kato.native/kato.native.cjvmti/pom.xml (with props)
incubator/kato/trunk/org.apache.kato/kato.native/kato.native.cjvmti/src/
incubator/kato/trunk/org.apache.kato/kato.native/kato.native.cjvmti/src/main/
incubator/kato/trunk/org.apache.kato/kato.native/kato.native.cjvmti/src/main/native/
incubator/kato/trunk/org.apache.kato/kato.native/kato.native.cjvmti/src/main/native/addClass.c
incubator/kato/trunk/org.apache.kato/kato.native/kato.native.cjvmti/src/main/native/addField.c
incubator/kato/trunk/org.apache.kato/kato.native/kato.native.cjvmti/src/main/native/addObject.c
incubator/kato/trunk/org.apache.kato/kato.native/kato.native.cjvmti/src/main/native/addThreads.c
incubator/kato/trunk/org.apache.kato/kato.native/kato.native.cjvmti/src/main/native/cjvmti.c
incubator/kato/trunk/org.apache.kato/kato.native/kato.native.cjvmti/src/main/native/include/
incubator/kato/trunk/org.apache.kato/kato.native/kato.native.cjvmti/src/main/native/include/addClass.h
incubator/kato/trunk/org.apache.kato/kato.native/kato.native.cjvmti/src/main/native/include/addField.h
incubator/kato/trunk/org.apache.kato/kato.native/kato.native.cjvmti/src/main/native/include/addObject.h
incubator/kato/trunk/org.apache.kato/kato.native/kato.native.cjvmti/src/main/native/include/addThreads.h
incubator/kato/trunk/org.apache.kato/kato.native/kato.native.cjvmti/src/main/native/include/cjvmti.h
incubator/kato/trunk/org.apache.kato/kato.native/kato.native.cjvmti/src/main/native/include/queue.h
incubator/kato/trunk/org.apache.kato/kato.native/kato.native.cjvmti/src/main/native/queue.c
incubator/kato/trunk/org.apache.kato/kato.native/kato.native.cjvmti/win32/
incubator/kato/trunk/org.apache.kato/kato.native/kato.native.cjvmti/win32/pom.xml (with props)
incubator/kato/trunk/org.apache.kato/kato.native/pom.xml (with props)
incubator/kato/trunk/org.apache.kato/kato.native/target/
incubator/kato/trunk/org.apache.kato/kato.native/target/classes/
Modified:
incubator/kato/trunk/org.apache.kato/kato.cjvmti/pom.xml
incubator/kato/trunk/org.apache.kato/pom.xml
Modified: incubator/kato/trunk/org.apache.kato/kato.cjvmti/pom.xml
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/org.apache.kato/kato.cjvmti/pom.xml?rev=812050&r1=812049&r2=812050&view=diff
==============================================================================
--- incubator/kato/trunk/org.apache.kato/kato.cjvmti/pom.xml (original)
+++ incubator/kato/trunk/org.apache.kato/kato.cjvmti/pom.xml Mon Sep 7 09:20:52 2009
@@ -6,8 +6,9 @@
</parent>
<modelVersion>4.0.0</modelVersion>
<groupId>org.apache.kato</groupId>
- <artifactId>kato.jvmti</artifactId>
+ <artifactId>kato.cjvmti</artifactId>
<version>0.0.1-SNAPSHOT</version>
+ <name>Java CJVMTI dump reader</name>
<dependencies>
<dependency>
<groupId>org.apache.kato</groupId>
Added: incubator/kato/trunk/org.apache.kato/kato.native/.classpath
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/org.apache.kato/kato.native/.classpath?rev=812050&view=auto
==============================================================================
--- incubator/kato/trunk/org.apache.kato/kato.native/.classpath (added)
+++ incubator/kato/trunk/org.apache.kato/kato.native/.classpath Mon Sep 7 09:20:52 2009
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
+ <classpathentry kind="con" path="org.maven.ide.eclipse.MAVEN2_CLASSPATH_CONTAINER"/>
+ <classpathentry kind="output" path="target/classes"/>
+</classpath>
Propchange: incubator/kato/trunk/org.apache.kato/kato.native/.classpath
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: incubator/kato/trunk/org.apache.kato/kato.native/.project
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/org.apache.kato/kato.native/.project?rev=812050&view=auto
==============================================================================
--- incubator/kato/trunk/org.apache.kato/kato.native/.project (added)
+++ incubator/kato/trunk/org.apache.kato/kato.native/.project Mon Sep 7 09:20:52 2009
@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>kato.native</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.maven.ide.eclipse.maven2Builder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ <nature>org.maven.ide.eclipse.maven2Nature</nature>
+ </natures>
+</projectDescription>
Propchange: incubator/kato/trunk/org.apache.kato/kato.native/.project
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: incubator/kato/trunk/org.apache.kato/kato.native/.settings/org.eclipse.jdt.core.prefs
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/org.apache.kato/kato.native/.settings/org.eclipse.jdt.core.prefs?rev=812050&view=auto
==============================================================================
--- incubator/kato/trunk/org.apache.kato/kato.native/.settings/org.eclipse.jdt.core.prefs (added)
+++ incubator/kato/trunk/org.apache.kato/kato.native/.settings/org.eclipse.jdt.core.prefs Mon Sep 7 09:20:52 2009
@@ -0,0 +1,5 @@
+#Mon Sep 07 09:19:50 BST 2009
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.source=1.6
+org.eclipse.jdt.core.compiler.compliance=1.6
Propchange: incubator/kato/trunk/org.apache.kato/kato.native/.settings/org.eclipse.jdt.core.prefs
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: incubator/kato/trunk/org.apache.kato/kato.native/.settings/org.maven.ide.eclipse.prefs
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/org.apache.kato/kato.native/.settings/org.maven.ide.eclipse.prefs?rev=812050&view=auto
==============================================================================
--- incubator/kato/trunk/org.apache.kato/kato.native/.settings/org.maven.ide.eclipse.prefs (added)
+++ incubator/kato/trunk/org.apache.kato/kato.native/.settings/org.maven.ide.eclipse.prefs Mon Sep 7 09:20:52 2009
@@ -0,0 +1,9 @@
+#Mon Sep 07 09:19:50 BST 2009
+version=1
+resolveWorkspaceProjects=true
+activeProfiles=
+eclipse.preferences.version=1
+fullBuildGoals=process-test-resources
+resourceFilterGoals=process-resources resources\:testResources
+includeModules=false
+skipCompilerPlugin=true
Propchange: incubator/kato/trunk/org.apache.kato/kato.native/.settings/org.maven.ide.eclipse.prefs
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: incubator/kato/trunk/org.apache.kato/kato.native/kato.native.cjvmti/.classpath
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/org.apache.kato/kato.native/kato.native.cjvmti/.classpath?rev=812050&view=auto
==============================================================================
--- incubator/kato/trunk/org.apache.kato/kato.native/kato.native.cjvmti/.classpath (added)
+++ incubator/kato/trunk/org.apache.kato/kato.native/kato.native.cjvmti/.classpath Mon Sep 7 09:20:52 2009
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
+ <classpathentry kind="con" path="org.maven.ide.eclipse.MAVEN2_CLASSPATH_CONTAINER"/>
+ <classpathentry kind="output" path="target/classes"/>
+</classpath>
Propchange: incubator/kato/trunk/org.apache.kato/kato.native/kato.native.cjvmti/.classpath
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: incubator/kato/trunk/org.apache.kato/kato.native/kato.native.cjvmti/.project
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/org.apache.kato/kato.native/kato.native.cjvmti/.project?rev=812050&view=auto
==============================================================================
--- incubator/kato/trunk/org.apache.kato/kato.native/kato.native.cjvmti/.project (added)
+++ incubator/kato/trunk/org.apache.kato/kato.native/kato.native.cjvmti/.project Mon Sep 7 09:20:52 2009
@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>kato.native.cjvmti</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.maven.ide.eclipse.maven2Builder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ <nature>org.maven.ide.eclipse.maven2Nature</nature>
+ </natures>
+</projectDescription>
Propchange: incubator/kato/trunk/org.apache.kato/kato.native/kato.native.cjvmti/.project
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: incubator/kato/trunk/org.apache.kato/kato.native/kato.native.cjvmti/.settings/org.eclipse.jdt.core.prefs
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/org.apache.kato/kato.native/kato.native.cjvmti/.settings/org.eclipse.jdt.core.prefs?rev=812050&view=auto
==============================================================================
--- incubator/kato/trunk/org.apache.kato/kato.native/kato.native.cjvmti/.settings/org.eclipse.jdt.core.prefs (added)
+++ incubator/kato/trunk/org.apache.kato/kato.native/kato.native.cjvmti/.settings/org.eclipse.jdt.core.prefs Mon Sep 7 09:20:52 2009
@@ -0,0 +1,5 @@
+#Thu Sep 03 09:16:58 BST 2009
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.source=1.6
+org.eclipse.jdt.core.compiler.compliance=1.6
Propchange: incubator/kato/trunk/org.apache.kato/kato.native/kato.native.cjvmti/.settings/org.eclipse.jdt.core.prefs
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: incubator/kato/trunk/org.apache.kato/kato.native/kato.native.cjvmti/.settings/org.maven.ide.eclipse.prefs
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/org.apache.kato/kato.native/kato.native.cjvmti/.settings/org.maven.ide.eclipse.prefs?rev=812050&view=auto
==============================================================================
--- incubator/kato/trunk/org.apache.kato/kato.native/kato.native.cjvmti/.settings/org.maven.ide.eclipse.prefs (added)
+++ incubator/kato/trunk/org.apache.kato/kato.native/kato.native.cjvmti/.settings/org.maven.ide.eclipse.prefs Mon Sep 7 09:20:52 2009
@@ -0,0 +1,9 @@
+#Thu Sep 03 09:16:57 BST 2009
+version=1
+resolveWorkspaceProjects=true
+activeProfiles=
+eclipse.preferences.version=1
+fullBuildGoals=process-test-resources
+resourceFilterGoals=process-resources resources\:testResources
+includeModules=false
+skipCompilerPlugin=true
Propchange: incubator/kato/trunk/org.apache.kato/kato.native/kato.native.cjvmti/.settings/org.maven.ide.eclipse.prefs
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: incubator/kato/trunk/org.apache.kato/kato.native/kato.native.cjvmti/linux-x86/pom.xml
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/org.apache.kato/kato.native/kato.native.cjvmti/linux-x86/pom.xml?rev=812050&view=auto
==============================================================================
--- incubator/kato/trunk/org.apache.kato/kato.native/kato.native.cjvmti/linux-x86/pom.xml (added)
+++ incubator/kato/trunk/org.apache.kato/kato.native/kato.native.cjvmti/linux-x86/pom.xml Mon Sep 7 09:20:52 2009
@@ -0,0 +1,70 @@
+<project>
+
+ <modelVersion>4.0.0</modelVersion>
+ <description>Create Linux X86 version of libcjvmti library</description>
+
+ <parent>
+ <groupId>org.apache.kato</groupId>
+ <artifactId>kato.native.cjvmti</artifactId>
+ <version>0.0.1-SNAPSHOT</version>
+ </parent>
+
+ <groupId>org.apache.kato.native</groupId>
+
+
+
+
+ <artifactId>libcjvmti</artifactId>
+
+ <name>Linux X86 Version of CJVMTI Native Library</name>
+
+ <packaging>so</packaging>
+
+
+
+
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.codehaus.mojo</groupId>
+ <artifactId>native-maven-plugin</artifactId>
+ <extensions>true</extensions>
+ <configuration>
+ <compilerStartOptions>
+ <compilerStartOption>-fPIC -O</compilerStartOption>
+ </compilerStartOptions>
+
+ <javahOS>linux</javahOS>
+
+ <sources>
+ <source>
+ <directory>${native.source.dir}</directory>
+ <fileNames>
+ <fileName>cjvmti.c</fileName>
+ <fileName>addClass.c</fileName>
+ <fileName>addField.c</fileName>
+ <fileName>addObject.c</fileName>
+ <fileName>addThreads.c</fileName>
+ <fileName>queue.c</fileName>
+ </fileNames>
+ </source>
+ <source>
+ <directory>${native.source.dir}/include</directory>
+ </source>
+ </sources>
+
+ <linkerStartOptions>
+ <linkerStartOption>-shared</linkerStartOption>
+ </linkerStartOptions>
+
+ </configuration>
+
+ </plugin>
+
+ </plugins>
+
+ </build>
+
+
+</project>
Propchange: incubator/kato/trunk/org.apache.kato/kato.native/kato.native.cjvmti/linux-x86/pom.xml
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: incubator/kato/trunk/org.apache.kato/kato.native/kato.native.cjvmti/linux-x86/target/libcjvmti.so
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/org.apache.kato/kato.native/kato.native.cjvmti/linux-x86/target/libcjvmti.so?rev=812050&view=auto
==============================================================================
Binary file - no diff available.
Propchange: incubator/kato/trunk/org.apache.kato/kato.native/kato.native.cjvmti/linux-x86/target/libcjvmti.so
------------------------------------------------------------------------------
svn:executable = *
Propchange: incubator/kato/trunk/org.apache.kato/kato.native/kato.native.cjvmti/linux-x86/target/libcjvmti.so
------------------------------------------------------------------------------
svn:mime-type = application/octet-stream
Added: incubator/kato/trunk/org.apache.kato/kato.native/kato.native.cjvmti/pom.xml
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/org.apache.kato/kato.native/kato.native.cjvmti/pom.xml?rev=812050&view=auto
==============================================================================
--- incubator/kato/trunk/org.apache.kato/kato.native/kato.native.cjvmti/pom.xml (added)
+++ incubator/kato/trunk/org.apache.kato/kato.native/kato.native.cjvmti/pom.xml Mon Sep 7 09:20:52 2009
@@ -0,0 +1,64 @@
+<project>
+
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>org.apache.kato</groupId>
+ <artifactId>kato.native.cjvmti</artifactId>
+ <version>0.0.1-SNAPSHOT</version>
+ <name>CJVMTI Native Library</name>
+
+ <packaging>pom</packaging>
+
+ <properties>
+ <native.source.dir>../src/main/native</native.source.dir>
+ </properties>
+
+ <profiles>
+
+ <profile>
+ <id>add-windows-x86-module</id>
+ <activation>
+ <os>
+ <family>windows</family>
+ <arch>x86</arch>
+ </os>
+ </activation>
+ <modules>
+ <module>win32</module>
+ </modules>
+ </profile>
+
+ <profile>
+ <id>add-linux-x86-module</id>
+ <activation>
+ <os>
+ <family>Linux</family>
+ <arch>i386</arch>
+ </os>
+ </activation>
+ <modules>
+ <module>linux-x86</module>
+ </modules>
+ </profile>
+
+
+ <!-- use this during release:prepare -->
+ <profile>
+ <id>all</id>
+ <activation>
+ <property>
+ <name>platform</name>
+ <value>all</value>
+ </property>
+ </activation>
+ <modules>
+ <module>win32</module>
+ <module>linux-x86</module>
+ <module>solaris</module>
+ </modules>
+ </profile>
+
+ </profiles>
+
+
+
+</project>
Propchange: incubator/kato/trunk/org.apache.kato/kato.native/kato.native.cjvmti/pom.xml
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: incubator/kato/trunk/org.apache.kato/kato.native/kato.native.cjvmti/src/main/native/addClass.c
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/org.apache.kato/kato.native/kato.native.cjvmti/src/main/native/addClass.c?rev=812050&view=auto
==============================================================================
--- incubator/kato/trunk/org.apache.kato/kato.native/kato.native.cjvmti/src/main/native/addClass.c (added)
+++ incubator/kato/trunk/org.apache.kato/kato.native/kato.native.cjvmti/src/main/native/addClass.c Mon Sep 7 09:20:52 2009
@@ -0,0 +1,528 @@
+/*******************************************************************************
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ ******************************************************************************/
+
+
+#include "cjvmti.h"
+#include "addClass.h"
+#include "addField.h"
+#include "addObject.h"
+
+struct JClass * addClassDetails(jclass class) {
+ jint field_count;
+ jvmtiError err;
+ jfieldID * fields;
+ char * name_ptr = NULL;
+ char * signature_ptr = NULL;
+ char * genSig_ptr = NULL;
+ char * sourceFileName = NULL;
+ jlong tag;
+ struct JClass * jcls = NULL;
+ struct JObject * oldObj = NULL;
+ int i;
+ int staticFieldCount = 0;
+ int instanceFieldCount = 0;
+ int countUp;
+ int classObject;
+ jint modifiers;
+ jint statusP;
+
+ jint interfaceCount;
+ jclass * interfaces = NULL;
+ struct JClass * interfaceClass = NULL;
+
+ jint classMods;
+
+
+ FPOS_T fieldPos;
+ FPOS_T fieldPosCheck;
+
+
+ int level = 0;
+ int subLevel = 0;
+ jclass superClazz;
+
+ printDepth++;
+ if (class == 0) {
+ return NULL;
+ }
+ statusP = 0;
+ /// Try do something with this before the call...
+
+ err = (*env)->GetClassStatus(env, class, &statusP);
+ if (err != JVMTI_ERROR_NONE){
+ printf("Class is not loaded \n");
+ return NULL;
+ }
+ //printf("Status %d \n", statusP);
+ (*env)->GetClassModifiers(env, class, &classMods);
+ //if (statusP == 0 || statusP & 8){
+ if (!(statusP == 7 || statusP == 16 || statusP == 32 || (statusP == 3 && (classMods & 0x0200 || classMods & 0x0400)))){
+ if (statusP & 8){
+ printf("Invalid class: loading error \n");}
+ return NULL;
+ }
+
+ err = (*env)->GetTag(env, class, &tag);
+ if (err != JVMTI_ERROR_NONE) {
+ printDepth--;
+ return NULL;
+ }
+ classObject = 0;
+ if (tag!=0){
+ oldObj = (void *)tag;
+ if (!oldObj->isClass){
+ classObject = 1;
+ oldObj->isClass = 1;
+ }
+ }
+
+
+
+ // Follow class hierarchy from the bottom up, reduces recursion which isn't currently prevented on classes, only object
+ if (tag == 0 || classObject) {
+ FSEEK(variableFile, 0, SEEK_END);
+ superClazz = class;
+ while (superClazz != 0) {
+ level++;
+ superClazz = (*jniptr)->GetSuperclass(jniptr, superClazz);
+ }
+ superClazz = class;
+ while (level != 0) {
+ superClazz = class;
+ subLevel = level;
+ while (subLevel != 0) {
+ superClazz = (*jniptr)->GetSuperclass(jniptr, superClazz);
+ subLevel--;
+ }
+ level--;
+ if (superClazz == 0) {
+ } else {
+ addClassDetails(superClazz);
+ }
+ FSEEK(variableFile, 0, SEEK_END);
+ }
+
+ addClassDetails((*jniptr)->GetSuperclass(jniptr, class)); // Ensure we know everything about this class hierarchy before beginning
+ FSEEK(variableFile, 0, SEEK_END);
+ err = (*env)->GetClassSignature(env, class, &name_ptr, &genSig_ptr);
+ if (err != JVMTI_ERROR_NONE){
+ printf(" ERROR ! \n ");
+ abort();
+ }
+ printfd("--- Not seen this class before, allocate %s ---\n", name_ptr);
+ tag = (long) (struct JClass *) calloc(1, sizeof(struct JClass));
+ if (tag == (long) NULL) {
+ printfd("--- Failed to malloc ---\n");
+ printDepth--;
+ abort();
+ return NULL;
+ }
+
+ err = (*env)->SetTag(env, class, tag);
+ Q_enqueue(&class, toDetag);
+ jcls = (void *) tag;
+ if (classObject){
+ // TODO free old object memory!
+ jcls->obj = (*oldObj);
+ free(oldObj);
+ }
+ jcls->positionInFile = FTELL(variableFile);
+ jcls->obj.isClass = 1;
+ staticsCount++;
+
+ writeIDNoSize(CJVMTI_CLASS, variableFile);
+ writeJint(classMods, variableFile);
+ writeString(name_ptr, variableFile);
+ //printf(" %s \n", name_ptr);
+
+ sourceFileName = 0;
+ err = (*env)->GetSourceFileName(env, class, &sourceFileName);
+ if (err != JVMTI_ERROR_NONE || sourceFileName == 0) {
+ writeString("NoSource", variableFile);
+ } else {
+ writeString(sourceFileName, variableFile);
+ (*env)->Deallocate(env, (unsigned char*)sourceFileName);
+ }
+ if (genSig_ptr != 0){
+ writeString(genSig_ptr, variableFile);
+ (*env)->Deallocate(env, (unsigned char*)genSig_ptr);
+ }else {
+ writeString(" ", variableFile);
+ }
+ } else {
+ jcls = (void *) tag;
+ printDepth--;
+ return jcls;
+ }
+
+ err = (*env)->GetClassFields(env, class, &field_count, &fields);
+ if (err != JVMTI_ERROR_NONE) {
+ jcls->numInstanceFields = 0;
+ printDepth--;
+ printf(" No class fields \n");
+ abort();
+ return jcls;
+ }
+
+ addMethodDetails(class);
+
+ jcls->name = name_ptr;
+ name_ptr = NULL;
+
+ // get field type counts
+ for (i = 0; i < field_count; i++) {
+ err = (*env)->GetFieldModifiers(env, class, fields[i], &modifiers);
+ assert(err == JVMTI_ERROR_NONE);
+ if (modifiers & 0x0008) {
+ staticFieldCount++;
+ } else {
+ instanceFieldCount++;
+ }
+ }
+ jcls->numStaticFields = staticFieldCount;
+ // malloc space for them..
+ jcls->numInstanceFields = instanceFieldCount;
+ jcls->instanceModifiers
+ = (jint *) malloc(sizeof(jint) * instanceFieldCount);
+ jcls->instanceFieldGenSig = (char * *) malloc(sizeof(char *)
+ * instanceFieldCount);
+ jcls->instanceFieldSignatures = (char * *) malloc(sizeof(char *)
+ * instanceFieldCount);
+ jcls->instanceFields = (jfieldID *) malloc(sizeof(jfieldID)
+ * instanceFieldCount);
+
+ if (jcls->instanceFields == NULL) {
+ printfd("--- Malloc failed end Class details ---\n");
+ abort();
+ printDepth--;
+ return NULL;
+ }
+
+ writeIDNoSize(CJVMTI_CLASS_INSTANCE_FIELDS, variableFile);
+ writeJint(instanceFieldCount, variableFile);
+
+ // occupy struct with instance fields so we can save objects correctly and also write out to file
+ countUp = 0;
+ for (i = 0; i < field_count; i++) {
+ (*env)->GetFieldModifiers(env, class, fields[i], &modifiers);
+ if (!(modifiers & 0x0008)) {
+ err = (*env)->GetFieldName(env, class, fields[i], &name_ptr,
+ &signature_ptr, &genSig_ptr);
+ if (err != JVMTI_ERROR_NONE) {
+ printf("Error getting field name \n");
+ abort();
+ break;
+ }
+
+ writeJint(modifiers, variableFile);
+ writeReference((FPOS_T) fields[i], variableFile);
+ writeString(name_ptr, variableFile);
+ writeString(signature_ptr, variableFile);
+ if (genSig_ptr == 0) {
+ writeString(" ", variableFile);
+ } else {
+ writeString(genSig_ptr, variableFile);
+ }
+
+ printfd("Field %s type %s \n", name_ptr, signature_ptr);
+ instanceFieldCount--;
+ assert(instanceFieldCount > -1);
+ jcls->instanceFields[countUp] = fields[i];
+ jcls->instanceFieldSignatures[countUp] = signature_ptr;
+ if ((genSig_ptr) != 0) {
+ jcls->instanceFieldGenSig[countUp] = genSig_ptr;
+ } else {
+ jcls->instanceFieldGenSig[countUp] = 0;
+ }
+ jcls->instanceModifiers[countUp] = modifiers;
+ countUp++;
+
+ (*env)->Deallocate(env, (unsigned char*)name_ptr);
+ name_ptr = NULL;
+ }
+ }
+
+ writeIDNoSize(CJVMTI_CLASS_STATIC_FIELDS, variableFile);
+ writeJint(staticFieldCount, variableFile);
+
+ // write out static field details
+ for (i = 0; i < field_count; i++) {
+ (*env)->GetFieldModifiers(env, class, fields[i], &modifiers);
+ if ((modifiers & 0x0008)) {
+ err = (*env)->GetFieldName(env, class, fields[i], &name_ptr,
+ &signature_ptr, &genSig_ptr);
+ if (err != JVMTI_ERROR_NONE) {
+ printfd("Getting field name for class error %d\n", err);
+ break;
+ }
+
+ writeJint(modifiers, variableFile);
+ writeReference((FPOS_T) fields[i], variableFile);
+ writeString(name_ptr, variableFile);
+ writeString(signature_ptr, variableFile);
+ if (genSig_ptr == 0) {
+ writeString(" ", variableFile);
+ } else {
+ writeString(genSig_ptr, variableFile);
+ (*env)->Deallocate(env, (unsigned char*)genSig_ptr);
+ }
+ (*env)->Deallocate(env, (unsigned char*)name_ptr);
+ (*env)->Deallocate(env, (unsigned char*)signature_ptr);
+ }
+ }
+
+ jcls->staticFieldLoc = (FPOS_T *) malloc(sizeof(FPOS_T) * staticFieldCount); // References to static fields
+
+ // make space for all references in file.
+ fieldPos = FTELL(variableFile);
+ writeIDNoSize(CJVMTI_SUPERCLASS_FIELDS, variableFile);
+ fwrite(&waitingToBeWritten, sizeof(FPOS_T), 1, variableFile); // super class reference
+
+ // Work out space needed for interface references
+ err = (*env)->GetImplementedInterfaces(env, class, &interfaceCount, &interfaces);
+ if (err != JVMTI_ERROR_NONE){
+ interfaceCount = 0;
+ }
+ writeIDNoSize(CJVMTI_CLASS_INTERFACES, variableFile);
+ writeJint(interfaceCount, variableFile);
+ for (i = 0; i < interfaceCount; i++) {
+ fwrite(&waitingToBeWritten, sizeof(FPOS_T), 1, variableFile);
+ }
+
+ writeIDNoSize(CJVMTI_CLASS_STATIC_FIELDS, variableFile);
+ for (i = 0; i < staticFieldCount; i++) {
+ fwrite(&waitingToBeWritten, sizeof(FPOS_T), 1, variableFile);
+ }
+
+
+ writeIDNoSize(CJVMTI_CLASSLOADERS, variableFile);
+ fwrite(&waitingToBeWritten, sizeof(FPOS_T), 1, variableFile); // class loader reference
+
+
+ FGETPOS(variableFile, &fieldPosCheck); //Alignment check for end
+
+ FSEEK(variableFile, 0, SEEK_END);
+ jcls->superClass = addClassDetails((*jniptr)->GetSuperclass(jniptr, class));
+ FSETPOS(variableFile, &fieldPos);
+
+ writeIDNoSize(CJVMTI_SUPERCLASS_FIELDS, variableFile);
+ if (jcls->superClass == 0) {
+ writeReference(CJVMTI_NULL_OBJECT, variableFile);
+ } else {
+ writeReference(jcls->superClass->positionInFile, variableFile);
+ }
+
+ writeIDNoSize(CJVMTI_CLASS_INTERFACES, variableFile);
+ writeJint(interfaceCount, variableFile);
+ fieldPos = FTELL(variableFile);
+ FSEEK(variableFile, 0, SEEK_END);
+ for (i = 0; i < interfaceCount; i++) {
+ interfaceClass = addClassDetails(interfaces[i]);
+ FSETPOS(variableFile, &fieldPos);
+ writeReference(interfaceClass->positionInFile, variableFile);
+ fieldPos = FTELL(variableFile);
+ FSEEK(variableFile, 0, SEEK_END);
+ }
+ if (interfaceCount > 0)(*env)->Deallocate(env, (unsigned char*)interfaces);
+ (*env)->Deallocate(env, (unsigned char*)fields);
+
+ jcls->staticFieldStart = fieldPos;
+ FSEEK(variableFile, 0, SEEK_END);
+ Q_enqueue(&class, qStaticFields);
+ return jcls;
+}
+
+struct JClass * addStaticFields(jclass class) {
+ FPOS_T fieldPos;
+ jfieldID * fields = NULL;
+ jint field_count;
+ int i;
+ jint err;
+ char * name_ptr = NULL;
+ char * signature_ptr = NULL;
+ char * genSig_ptr = NULL;
+ jint modifiers;
+ int staticFieldCount;
+ jobject classloader;
+
+ struct JClass * jcls = addClassDetails(class);
+ if (jcls == NULL) {
+ return NULL;
+ }
+ if (jcls->filledIn) {
+ return jcls;
+ }
+ staticFieldCount = jcls->numStaticFields;
+ FSEEK(variableFile, jcls->staticFieldStart, SEEK_SET);
+ writeIDNoSize(CJVMTI_CLASS_STATIC_FIELDS, variableFile);
+ fieldPos = FTELL(variableFile);
+ FSEEK(variableFile, 0, SEEK_END);
+ err = (*env)->GetClassFields(env, class, &field_count, &fields);
+ (*env)->GetClassLoader(env, class, &classloader);
+
+ for (i = 0; i < field_count; i++) {
+ err = (*env)->GetFieldName(env, class, fields[i], &name_ptr,
+ &signature_ptr, &genSig_ptr);
+ if (err != JVMTI_ERROR_NONE) {
+ printf("Getting field name for class error %d\n", err);
+ abort();
+ break;
+ }
+ // check if field is static
+ (*env)->GetFieldModifiers(env, class, fields[i], &modifiers);
+ if (modifiers & 0x0008) {
+ staticFieldCount--;
+
+ jcls->staticFieldLoc[staticFieldCount]
+ = addFieldValue(CJVMTI_STATIC_VAR, class, fields[i],
+ signature_ptr, 0, 0, 0);
+ FSETPOS(variableFile, &fieldPos);
+ writeReference(jcls->staticFieldLoc[staticFieldCount], variableFile);
+
+ // check its adding a true reference
+ if (jcls->staticFieldLoc[staticFieldCount] == waitingToBeWritten) {
+ printf("Circular reference, abort \n");
+ abort();
+ }
+ fieldPos = FTELL(variableFile);
+ FSEEK(variableFile, 0, SEEK_END);
+ }
+
+ (*env)->Deallocate(env, (unsigned char *) name_ptr);
+ (*env)->Deallocate(env, (unsigned char *) signature_ptr);
+ (*env)->Deallocate(env, (unsigned char *) genSig_ptr);
+ }
+
+ // write class loader details to file
+
+ FSEEK(variableFile, 0, SEEK_END);
+ if (classloader != 0) {
+ jcls->classLoader = addObject(classloader)->positionInFile;
+ } else {
+ jcls->classLoader = CJVMTI_NULL_OBJECT;
+ }
+ FSETPOS(variableFile, &fieldPos);
+ writeIDNoSize(CJVMTI_CLASSLOADERS, variableFile);
+ writeReference(jcls->classLoader, variableFile);
+ fieldPos = FTELL(variableFile);
+ FSEEK(variableFile, 0, SEEK_END);
+
+ printDepth--;
+ jcls->filledIn = 1;
+ staticsCount--;
+ (*env)->Deallocate(env, (unsigned char *)fields);
+ return jcls;
+}
+
+
+
+
+
+
+
+int addMethodDetails(jclass class) {
+ jint method_count;
+ jmethodID * method_ptr;
+ jvmtiError err;
+ char * mname = NULL;
+ char * msig = NULL;
+ char * mgenSig = NULL;
+ jint varCount;
+ jvmtiLocalVariableEntry * table = NULL;
+ jvmtiLineNumberEntry * lnt_ptr = NULL;
+ jint modifiers;
+ int i;
+ int i2;
+
+ writeIDNoSize(CJVMTI_METHOD, variableFile);
+ err = (*env)->GetClassMethods(env, class, &method_count, &method_ptr);
+ if (err != JVMTI_ERROR_NONE) {
+ method_count = 0;
+ }
+ writeJint(method_count, variableFile);
+ for (i = 0; i < method_count; i++) {
+ writeIDNoSize(CJVMTI_METHOD, variableFile);
+ err
+ = (*env)->GetMethodName(env, method_ptr[i], &mname, &msig,
+ &mgenSig);
+ if (err != JVMTI_ERROR_NONE) {
+ mname = "Missing";
+ continue;
+ }
+ writeReference((FPOS_T) method_ptr[i], variableFile);
+ writeString(mname, variableFile);
+ writeString(msig, variableFile);
+ (*env)->Deallocate(env, (unsigned char *) mname);
+ (*env)->Deallocate(env, (unsigned char *) msig);
+ if (mgenSig != 0) {
+ writeString(mgenSig, variableFile);
+ (*env)->Deallocate(env, (unsigned char *) mgenSig);
+ } else {
+ writeString(" ", variableFile);
+ }
+ mname = NULL;
+ msig = NULL;
+ mgenSig = NULL;
+
+ err = (*env)->GetMethodModifiers(env, method_ptr[i], &modifiers);
+ writeJint(modifiers, variableFile);
+ err = (*env)->GetLocalVariableTable(env, method_ptr[i], &varCount,
+ &table);
+ if (err != JVMTI_ERROR_NONE) {
+ varCount = 0;
+ writeJint(0, variableFile);
+ } else {
+ writeJint(varCount, variableFile);
+ }
+ for (i2 = 0; i2 < varCount; i2++) {
+ writeString(table[i2].name, variableFile);
+ writeString(table[i2].signature, variableFile);
+ (*env)->Deallocate(env, (unsigned char *) table[i2].name);
+ (*env)->Deallocate(env, (unsigned char *) table[i2].signature);
+ if (table[i2].generic_signature != 0) {
+ writeString(table[i2].generic_signature, variableFile);
+ (*env)->Deallocate(env, (unsigned char *) table[i2].generic_signature);
+ } else {
+ writeString(" ", variableFile);
+ }
+ writeJint(table[i2].length, variableFile);
+ writeJint(table[i2].slot, variableFile);
+ writeReference(table[i2].start_location, variableFile);
+
+
+ }
+ if (err == JVMTI_ERROR_NONE && varCount > 0) (*env)->Deallocate(env, (unsigned char *) table);
+ table = NULL;
+
+ // Line number table
+ (*env)->GetLineNumberTable(env, method_ptr[i], &varCount, &lnt_ptr);
+ if (err != JVMTI_ERROR_NONE) {
+ writeJint(0, variableFile);
+ } else {
+ writeJint(varCount, variableFile);
+ for (i2 = 0; i2 < varCount; i2++) {
+ writeJint(lnt_ptr[i2].line_number, variableFile);
+ writeReference(lnt_ptr[i2].start_location, variableFile);
+ }
+ if (varCount > 0){
+ (*env)->Deallocate(env, (unsigned char *) lnt_ptr);
+ }
+ }
+
+ }
+
+ if (method_count > 0)(*env)->Deallocate(env, (unsigned char *) method_ptr);
+ return 1;
+}
+
Added: incubator/kato/trunk/org.apache.kato/kato.native/kato.native.cjvmti/src/main/native/addField.c
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/org.apache.kato/kato.native/kato.native.cjvmti/src/main/native/addField.c?rev=812050&view=auto
==============================================================================
--- incubator/kato/trunk/org.apache.kato/kato.native/kato.native.cjvmti/src/main/native/addField.c (added)
+++ incubator/kato/trunk/org.apache.kato/kato.native/kato.native.cjvmti/src/main/native/addField.c Mon Sep 7 09:20:52 2009
@@ -0,0 +1,475 @@
+/*******************************************************************************
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ ******************************************************************************/
+
+
+#include "cjvmti.h"
+#include "addObject.h"
+#include "addClass.h"
+FPOS_T addFieldValue(int type, jobject obj, jfieldID field, char * signature,
+ jthread thread, jint depth, jint slot) {
+
+ // Primitives
+ jbyte b;
+ jchar c;
+ jdouble d;
+ jfloat f;
+ jint i;
+ jlong j;
+ jobject l;
+ jshort s;
+ jboolean z;
+
+ // Arrays
+ jbyte * bArray;
+ jchar * cArray;
+ jdouble * dArray;
+ jfloat * fArray;
+ jint * iArray;
+ jlong * jArray;
+ jshort * sArray;
+ jboolean * zArray;
+ int szArray;
+ jobject arrayElement;
+
+ jboolean isCopy;
+
+ jvmtiError err;
+ int counter;
+ FPOS_T position = -1;
+ FPOS_T * arrayFields;
+ struct JClass * arrayType;
+ position = FTELL(variableFile);
+ switch (*signature) {
+ case 'B':
+ switch (type) {
+ case CJVMTI_INSTANCE_VAR:
+ b = (*jniptr)->GetByteField(jniptr, obj, field);
+ break;
+ case CJVMTI_LOCAL_VAR:
+ err = (*env)->GetLocalInt(env, thread, depth, slot, &i);
+ b = (jbyte) i;
+ break;
+ case CJVMTI_STATIC_VAR:
+ b = (*jniptr)->GetStaticByteField(jniptr, obj, field);
+ break;
+ }
+ printfd("Type %d %c %d \n", type, *signature, b);
+ writeIDNoSize(CJVMTI_BYTE, variableFile);
+ fwrite(&b, sizeof(jbyte), 1, variableFile);
+ break;
+ case 'C':
+ switch (type) {
+ case CJVMTI_INSTANCE_VAR:
+ c = (*jniptr)->GetCharField(jniptr, obj, field);
+ break;
+ case CJVMTI_LOCAL_VAR:
+ err = (*env)->GetLocalInt(env, thread, depth, slot, &i);
+ c = (jchar) i;
+ break;
+ case CJVMTI_STATIC_VAR:
+ c = (*jniptr)->GetStaticCharField(jniptr, obj, field);
+ break;
+ }
+ printfd("Type %d %c %c \n", type, *signature, c);
+ writeIDNoSize(CJVMTI_CHAR, variableFile);
+ fwrite(&c, sizeof(jchar), 1, variableFile);
+ break;
+ case 'D':
+ switch (type) {
+ case CJVMTI_INSTANCE_VAR:
+ d = (*jniptr)->GetDoubleField(jniptr, obj, field);
+ break;
+ case CJVMTI_LOCAL_VAR:
+ err = (*env)->GetLocalDouble(env, thread, depth, slot, &d);
+ break;
+ case CJVMTI_STATIC_VAR:
+ d = (*jniptr)->GetStaticDoubleField(jniptr, obj, field);
+ break;
+ }
+ printfd("Type %d %c %f \n", type, *signature, d);
+ writeIDNoSize(CJVMTI_DOUBLE, variableFile);
+ fwrite(&d, sizeof(jdouble), 1, variableFile);
+ break;
+ case 'F':
+ switch (type) {
+ case CJVMTI_INSTANCE_VAR:
+ f = (*jniptr)->GetFloatField(jniptr, obj, field);
+ break;
+ case CJVMTI_LOCAL_VAR:
+ err = (*env)->GetLocalFloat(env, thread, depth, slot, &f);
+ break;
+ case CJVMTI_STATIC_VAR:
+ f = (*jniptr)->GetStaticFloatField(jniptr, obj, field);
+ break;
+ }
+ printfd("Type %d %c %f \n", type, *signature, f);
+ writeIDNoSize(CJVMTI_FLOAT, variableFile);
+ fwrite(&f, sizeof(jfloat), 1, variableFile);
+
+ break;
+ case 'I':
+ switch (type) {
+ case CJVMTI_INSTANCE_VAR:
+ i = (*jniptr)->GetIntField(jniptr, obj, field);
+ break;
+ case CJVMTI_LOCAL_VAR:
+ err = (*env)->GetLocalInt(env, thread, depth, slot, &i);
+ break;
+ case CJVMTI_STATIC_VAR:
+ i = (*jniptr)->GetStaticIntField(jniptr, obj, field);
+ break;
+ }
+ printfd("Type %d %c %d \n", type, *signature, i);
+ writeIDNoSize(CJVMTI_INT, variableFile);
+ fwrite(&i, sizeof(jint), 1, variableFile);
+ break;
+ case 'J':
+ switch (type) {
+ case CJVMTI_INSTANCE_VAR:
+ j = (*jniptr)->GetLongField(jniptr, obj, field);
+ break;
+ case CJVMTI_LOCAL_VAR:
+ err = (*env)->GetLocalLong(env, thread, depth, slot, &j);
+ break;
+ case CJVMTI_STATIC_VAR:
+ j = (*jniptr)->GetStaticLongField(jniptr, obj, field);
+ break;
+ }
+ printfd("Type %d %c %ld \n", type, *signature, j);
+ writeIDNoSize(CJVMTI_LONG, variableFile);
+ fwrite(&j, sizeof(jlong), 1, variableFile);
+ break;
+ case 'L':
+ switch (type) {
+ case CJVMTI_INSTANCE_VAR:
+ l = (*jniptr)->GetObjectField(jniptr, obj, field);
+ break;
+ case CJVMTI_LOCAL_VAR:
+ err = (*env)->GetLocalObject(env, thread, depth, slot, &l);
+ if (err != JVMTI_ERROR_NONE) {
+ printfd("error %d\n", err);
+ }
+ break;
+ case CJVMTI_STATIC_VAR:
+ l = (*jniptr)->GetStaticObjectField(jniptr, obj, field);
+ break;
+ case CJVMTI_ARRAY_VAR:
+ l = obj;
+ }
+
+ if (l != 0) {
+ printfd("Type %d %s %d\n", type, signature, l);
+ position = addObject(l)->positionInFile;
+ printfd("Position %lld \n", position);
+ } else {
+ printfd(
+ "Null Object, need to standardise how to represent this..\n");
+ writeIDNoSize(CJVMTI_NULL_OBJECT, variableFile);
+ }
+ break;
+ case 'S':
+ switch (type) {
+ case CJVMTI_INSTANCE_VAR:
+ s = (*jniptr)->GetShortField(jniptr, obj, field);
+ break;
+ case CJVMTI_LOCAL_VAR:
+ err = (*env)->GetLocalInt(env, thread, depth, slot, &i);
+ s = (jshort) i;
+ break;
+ case CJVMTI_STATIC_VAR:
+ s = (*jniptr)->GetStaticShortField(jniptr, obj, field);
+ break;
+ }
+ printfd("Type %d %c %hd \n", type, *signature, s);
+ writeIDNoSize(CJVMTI_SHORT, variableFile);
+ fwrite(&s, sizeof(jshort), 1, variableFile);
+ break;
+ case 'Z':
+ switch (type) {
+ case CJVMTI_INSTANCE_VAR:
+ z = (*jniptr)->GetBooleanField(jniptr, obj, field);
+ break;
+ case CJVMTI_LOCAL_VAR:
+ err = (*env)->GetLocalInt(env, thread, depth, slot, &i);
+ z = (jboolean) i;
+ break;
+ case CJVMTI_STATIC_VAR:
+ z = (*jniptr)->GetStaticBooleanField(jniptr, obj, field);
+ break;
+ }
+ if (z) {
+ printfd("Type %d %c true \n", type, *signature);
+ } else {
+ printfd("Type %d %c false \n", type, *signature);
+ }
+ writeIDNoSize(CJVMTI_BOOLEAN, variableFile);
+ fwrite(&z, sizeof(jboolean), 1, variableFile);
+
+ break;
+ case '[':
+ signature++;
+ if ((*signature == 'L') || (*signature == '[')) {
+ switch (type) {
+ case CJVMTI_INSTANCE_VAR:
+ l = (*jniptr)->GetObjectField(jniptr, obj, field);
+ break;
+ case CJVMTI_LOCAL_VAR:
+ err = (*env)->GetLocalObject(env, thread, depth, slot, &l);
+ if (err != JVMTI_ERROR_NONE)
+ printfd("Error %d \n", err);
+ break;
+ case CJVMTI_STATIC_VAR:
+ l = (*jniptr)->GetStaticObjectField(jniptr, obj, field);
+ break;
+ case CJVMTI_ARRAY_VAR:
+ l = obj;
+ break;
+ }
+ if (l == 0) {
+ printfd("NULL array\n");
+ writeIDNoSize(CJVMTI_NULL_OBJECT, variableFile);
+ } else {
+ FSEEK(variableFile, 0, SEEK_END);
+ arrayType = addClassDetails(
+ (*jniptr)->GetObjectClass(jniptr, l));
+ szArray = (*jniptr)->GetArrayLength(jniptr, l);
+ arrayFields = NULL;
+ if (szArray > 0) {
+ arrayFields = malloc(sizeof(FPOS_T) * szArray);
+ for (counter = 0; counter < szArray; counter++) {
+ FSEEK(variableFile, 0, SEEK_END);
+ arrayElement = (*jniptr)->GetObjectArrayElement(jniptr,
+ l, counter);
+ if (arrayElement == 0) {
+ printfd("Null array element \n");
+ arrayFields[counter] = CJVMTI_NULL_OBJECT;
+ } else {
+ printfd("Follow array\n");
+ arrayFields[counter] = addFieldValue(
+ CJVMTI_ARRAY_VAR, arrayElement, 0,
+ (arrayType->name) + 1, 0, 0, 0);
+ }
+ }
+ }
+ FSEEK(variableFile, 0, SEEK_END);
+ position = FTELL(variableFile);
+ writeIDNoSize(CJVMTI_OBJECT_ARRAY, variableFile);
+ writeReference(arrayType->positionInFile, variableFile);
+ writeJint(szArray, variableFile);
+ if (szArray > 0) {
+ for (counter = 0; counter < szArray; counter++) {
+ if (arrayFields[counter] == 0) {
+ writeReference(CJVMTI_NULL_OBJECT, variableFile);
+ } else {
+ writeReference(arrayFields[counter], variableFile);
+ }
+ }
+ }
+ free(arrayFields);
+ }
+ break;
+ } else {
+ switch (type) {
+ case CJVMTI_INSTANCE_VAR:
+ l = (*jniptr)->GetObjectField(jniptr, obj, field);
+ break;
+ case CJVMTI_LOCAL_VAR:
+ err = (*env)->GetLocalObject(env, thread, depth, slot, &l);
+ if (err != JVMTI_ERROR_NONE)
+ printfd("Error %d \n", err);
+ break;
+ case CJVMTI_STATIC_VAR:
+ l = (*jniptr)->GetStaticObjectField(jniptr, obj, field);
+ break;
+ case CJVMTI_ARRAY_VAR:
+ l = obj;
+ break;
+ }
+ // TODO correct this, do we have a null object before we declare the class type, or use the signature..
+ printfd("get byte array \n");
+ if (l == 0) {
+ printfd("NULL primitive array\n");
+ writeIDNoSize(CJVMTI_NULL_OBJECT, variableFile);
+ break;
+ }
+ szArray = (*jniptr)->GetArrayLength(jniptr, l);
+
+ switch (*signature) {
+ // B byte signed byte
+ // C char Unicode character
+ // D double double-precision floating-point value
+ // F float single-precision floating-point value
+ // I int integer
+ // J long long integer
+ // S short signed short
+ // Z boolean true or false
+ case 'B':
+ if (l == 0) {
+ printfd("NULL primitive array\n");
+ writeIDNoSize(CJVMTI_NULL_OBJECT, variableFile);
+ } else {
+ writeIDNoSize(CJVMTI_BYTE_ARRAY, variableFile);
+ writeJint(szArray, variableFile);
+ bArray
+ = (*jniptr)->GetByteArrayElements(jniptr, l,
+ &isCopy);
+ printfd("");
+
+ for (counter = 0; counter < szArray; counter++) {
+ printfR("%d", bArray[counter]);
+ fwrite(&bArray[counter], sizeof(jbyte), 1, variableFile);
+ }
+ (*jniptr)->ReleaseByteArrayElements(jniptr, l, bArray,JNI_ABORT);
+ printfR("\n");
+ }
+ break;
+ case 'C':
+ if (l == 0) {
+ printfd("NULL primitive array\n");
+ writeIDNoSize(CJVMTI_NULL_OBJECT, variableFile);
+ } else {
+ writeIDNoSize(CJVMTI_CHAR_ARRAY, variableFile);
+ writeJint(szArray, variableFile);
+ cArray
+ = (*jniptr)->GetCharArrayElements(jniptr, l,
+ &isCopy);
+ printfd("");
+ for (counter = 0; counter < szArray; counter++) {
+ printfR("%c", cArray[counter]);
+ fwrite(&cArray[counter], sizeof(jchar), 1, variableFile);
+ }
+ (*jniptr)->ReleaseCharArrayElements(jniptr, l, cArray,JNI_ABORT);
+ printfR("\n");
+ }
+ break;
+ case 'D':
+ if (l == 0) {
+ printfd("NULL primitive array\n");
+ writeIDNoSize(CJVMTI_NULL_OBJECT, variableFile);
+ } else {
+ writeIDNoSize(CJVMTI_DOUBLE_ARRAY, variableFile);
+ writeJint(szArray, variableFile);
+
+ dArray = (*jniptr)->GetDoubleArrayElements(jniptr, l,
+ &isCopy);
+
+ printfd("");
+ for (counter = 0; counter < szArray; counter++) {
+ printfR("%f", dArray[counter]);
+ fwrite(&dArray[counter], sizeof(jdouble), 1,
+ variableFile);
+ }
+ (*jniptr)->ReleaseDoubleArrayElements(jniptr, l, dArray,JNI_ABORT);
+ printfR("\n");
+ }
+ break;
+ case 'F':
+ if (l == 0) {
+ printfd("NULL primitive array\n");
+ writeIDNoSize(CJVMTI_NULL_OBJECT, variableFile);
+ } else {
+ writeIDNoSize(CJVMTI_FLOAT_ARRAY, variableFile);
+ writeJint(szArray, variableFile);
+ fArray = (*jniptr)->GetFloatArrayElements(jniptr, l,
+ &isCopy);
+ printfd("");
+ for (counter = 0; counter < szArray; counter++) {
+ printfR("%f", fArray[counter]);
+ fwrite(&fArray[counter], sizeof(jfloat), 1,
+ variableFile);
+ }
+ (*jniptr)->ReleaseFloatArrayElements(jniptr, l, fArray,JNI_ABORT);
+ printfR("\n");
+ }
+ break;
+ case 'I':
+ if (l == 0) {
+ printfd("NULL primitive array\n");
+ writeIDNoSize(CJVMTI_NULL_OBJECT, variableFile);
+ } else {
+ writeIDNoSize(CJVMTI_INT_ARRAY, variableFile);
+ writeJint(szArray, variableFile);
+ iArray = (*jniptr)->GetIntArrayElements(jniptr, l, &isCopy);
+ printfd("");
+ for (counter = 0; counter < szArray; counter++) {
+ printfR("%d", iArray[counter]);
+ fwrite(&iArray[counter], sizeof(jint), 1, variableFile);
+ }
+ (*jniptr)->ReleaseIntArrayElements(jniptr, l, iArray,JNI_ABORT);
+ printfR("\n");
+ }
+ break;
+
+ case 'J':
+ if (l == 0) {
+ printfd("NULL primitive array\n");
+ writeIDNoSize(CJVMTI_NULL_OBJECT, variableFile);
+ } else {
+ writeIDNoSize(CJVMTI_LONG_ARRAY, variableFile);
+ writeJint(szArray, variableFile);
+ jArray
+ = (*jniptr)->GetLongArrayElements(jniptr, l,
+ &isCopy);
+ printfd("");
+ for (counter = 0; counter < szArray; counter++) {
+ printfR("%ld ", jArray[counter]);
+ fwrite(&jArray[counter], sizeof(jlong), 1, variableFile);
+ }
+ (*jniptr)->ReleaseLongArrayElements(jniptr, l, jArray,JNI_ABORT);
+ printfR("\n");
+ }
+ break;
+ case 'S':
+ if (l == 0) {
+ printfd("NULL primitive array\n");
+ writeIDNoSize(CJVMTI_NULL_OBJECT, variableFile);
+ } else {
+ writeIDNoSize(CJVMTI_SHORT_ARRAY, variableFile);
+ writeJint(szArray, variableFile);
+ sArray = (*jniptr)->GetShortArrayElements(jniptr, l,
+ &isCopy);
+ printfd("");
+ for (counter = 0; counter < szArray; counter++) {
+ printfR("%d ", sArray[counter]);
+ fwrite(&sArray[counter], sizeof(jshort), 1,
+ variableFile);
+ }
+ (*jniptr)->ReleaseShortArrayElements(jniptr, l, sArray,JNI_ABORT);
+ printfR("\n");
+ }
+ break;
+ case 'Z':
+ if (l == 0) {
+ printfd("NULL primitive array\n");
+ writeIDNoSize(CJVMTI_NULL_OBJECT, variableFile);
+ } else {
+ writeIDNoSize(CJVMTI_BOOLEAN_ARRAY, variableFile);
+ writeJint(szArray, variableFile);
+ zArray = (*jniptr)->GetBooleanArrayElements(jniptr, l,
+ &isCopy);
+ printfd("");
+ for (counter = 0; counter < szArray; counter++) {
+ printfR("%ld ", zArray[counter]);
+ fwrite(&zArray[counter], sizeof(jboolean), 1,
+ variableFile);
+ }
+ (*jniptr)->ReleaseBooleanArrayElements(jniptr, l, zArray,JNI_ABORT);
+ printfR("\n");
+ }
+ break;
+ }
+ }
+ }
+ return position;
+}
Added: incubator/kato/trunk/org.apache.kato/kato.native/kato.native.cjvmti/src/main/native/addObject.c
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/org.apache.kato/kato.native/kato.native.cjvmti/src/main/native/addObject.c?rev=812050&view=auto
==============================================================================
--- incubator/kato/trunk/org.apache.kato/kato.native/kato.native.cjvmti/src/main/native/addObject.c (added)
+++ incubator/kato/trunk/org.apache.kato/kato.native/kato.native.cjvmti/src/main/native/addObject.c Mon Sep 7 09:20:52 2009
@@ -0,0 +1,181 @@
+
+/*******************************************************************************
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ ******************************************************************************/
+
+
+#include "cjvmti.h"
+#include "addObject.h"
+#include "addClass.h"
+#include "addField.h"
+struct JObject * addObject(jobject obj) {
+ jclass clazz;
+ if (obj == 0){
+ printf("NULL object! \n");
+ abort();
+ return &nullObject;
+ }
+ clazz = (*jniptr)->GetObjectClass(jniptr, obj);
+ return getObjectInfo(clazz, obj);
+}
+
+
+struct JObject * getObjectInfo(jclass class, jobject obj) {
+ int i;
+ jlong tag;
+ jvmtiError err;
+ struct JClass * clazz;
+ struct JClass * tempClazz;
+ struct JObject * objp = NULL;
+ FPOS_T fieldValLoc;
+ jint totalFieldCount;
+ int classObject = 0;
+
+ if (obj == NULL || class == NULL) return &nullObject;
+ clazz = addClassDetails(class); // grab the declaring class and ensure hierarchy is built for fields
+ //addClassDetails(obj); // check if this is a class object
+ if (clazz == NULL){
+ return &nullObject;
+ }
+ if (clazz->positionInFile == 0) {
+ objp = (void *) clazz;
+ printf("Invalid class location %p %lld %lld \n", clazz,
+ objp->positionInFile, clazz->positionInFile);
+ printf(" %s, abort \n ", clazz->name);
+ abort();
+ }
+
+ printDepth++;
+
+ if (clazz == NULL) {
+ printfd("Null class, abort\n");
+ abort();
+ }
+
+ err = (*env)->GetTag(env, obj, &tag);
+ if (err != JVMTI_ERROR_NONE) {
+ printfR("Could not retrieve tag/object %d \n", err);
+ printDepth--;
+ return objp;
+ }
+
+ if (tag != 0) {
+ objp = (void *) tag;
+ if (!objp->state) {
+ objp->isClass = 1;
+ classObject = 1;
+ }else{
+ return objp;
+ }
+ }
+
+ if (tag == 0 || classObject) {
+ printfd("--- Not seen this object before, save it ---\n");
+ if (!classObject)
+ tag = (jlong) calloc(1, sizeof(struct JObject));
+ if ((void *) tag == NULL) {
+ printfd("--- Failed to malloc ---\n");
+ printDepth--;
+ return objp;
+ }
+
+ if (!classObject){
+ err = (*env)->SetTag(env, obj, tag);
+ Q_enqueue(&obj, toDetag);
+ }
+ if (err != JVMTI_ERROR_NONE) {
+ printf("JVMTI Error %d \n", err);
+ printDepth--;
+ return objp;
+ }
+ FSEEK(variableFile, 0, SEEK_END);
+
+ // Work out how many fields we need to save across the hierarchy
+ tempClazz = clazz;
+ totalFieldCount = 0;
+
+ while (tempClazz) {
+ totalFieldCount += tempClazz->numInstanceFields;
+ tempClazz = tempClazz->superClass;
+ }
+
+ objp = (void *) tag;
+ if (!classObject) objp->isClass = 0;
+ objp->state = 1;
+ FSEEK(variableFile, 0, SEEK_END);
+ objp->positionInFile = FTELL(variableFile);
+ writeIDNoSize(CJVMTI_OBJECT, variableFile);
+
+ writeReference(clazz->positionInFile, variableFile);
+ writeJint(totalFieldCount, variableFile);
+ fieldValLoc = FTELL(variableFile);
+ for (i = 0; i < totalFieldCount; i++) {
+ fwrite(&waitingToBeWritten, sizeof(FPOS_T), 1, variableFile);
+ }
+
+ objp->referenceLocation = fieldValLoc;
+ objp->totalFieldCount = totalFieldCount;
+ FSEEK(variableFile, 0, SEEK_END);
+ objectCount++;
+ Q_enqueue(&obj, qObjects);
+ }
+ return objp;
+}
+
+struct JObject * getObjectReferences(jobject obj) {
+ int i;
+ FPOS_T fieldValLoc;
+ FPOS_T fieldValue;
+ jlong tag;
+ struct JObject * objp;
+ struct JClass * clazz;
+ struct JClass * tempClazz;
+ int totalFieldCount;
+ (*env)->GetTag(env, obj, &tag);
+ objp = (struct JObject *) tag;
+ if (objp->state == 2) {
+ objectCount--;
+ return objp;
+ }
+ clazz = addClassDetails((*jniptr)->GetObjectClass(jniptr, obj));
+ totalFieldCount = objp->totalFieldCount;
+ fieldValLoc = objp->referenceLocation;
+ FSEEK(variableFile, 0, SEEK_END);
+ // Loop through saving the references to file
+ tempClazz = clazz;
+ while (tempClazz) {
+ // TODO We only need an array of max size of a superclass fields
+ for (i = 0; i < tempClazz->numInstanceFields; i++) {
+ fieldValue = addFieldValue(CJVMTI_INSTANCE_VAR, obj,
+ tempClazz->instanceFields[i],
+ tempClazz->instanceFieldSignatures[i], 0, 0, 0);
+ if (fieldValue == waitingToBeWritten){
+ printf("Error unwritten reference\n");
+ abort();
+ }
+ FSETPOS(variableFile, &fieldValLoc);
+ writeReference(fieldValue, variableFile);
+ if (fieldValue == waitingToBeWritten) {
+ printfd("Circular reference \n");
+ abort();
+ }
+ fieldValLoc = FTELL(variableFile);
+ FSEEK(variableFile, 0, SEEK_END);
+ }
+ tempClazz = tempClazz->superClass;
+ }
+ objectCount--;
+ objp->state = 2;
+ printDepth--;
+ return objp;
+}
Added: incubator/kato/trunk/org.apache.kato/kato.native/kato.native.cjvmti/src/main/native/addThreads.c
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/org.apache.kato/kato.native/kato.native.cjvmti/src/main/native/addThreads.c?rev=812050&view=auto
==============================================================================
--- incubator/kato/trunk/org.apache.kato/kato.native/kato.native.cjvmti/src/main/native/addThreads.c (added)
+++ incubator/kato/trunk/org.apache.kato/kato.native/kato.native.cjvmti/src/main/native/addThreads.c Mon Sep 7 09:20:52 2009
@@ -0,0 +1,256 @@
+/*******************************************************************************
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ ******************************************************************************/
+
+
+#include "cjvmti.h"
+#include "addObject.h"
+#include "addField.h"
+#include "addClass.h"
+
+int getLocVars(jmethodID methodID, jlocation loc, jthread * thread, int depth) {
+ int i = 0;
+ int aliveVarCount;
+ jvmtiError err;
+ jint varCount;
+ jvmtiLocalVariableEntry * table;
+ FPOS_T refLoc;
+ FPOS_T tempLoc;
+ aliveVarCount = 0;
+ printDepth++;
+ err = (*env)->GetLocalVariableTable(env, methodID, &varCount, &table);
+ if (err != JVMTI_ERROR_NONE) {
+ printfd("JVMTI Error \n");
+ writeIDNoSize(CJVMTI_JVMTI_ERROR, variableFile);
+ printDepth--;
+ return 0;
+ }
+ if (loc == -1) {
+ printfd("Executing native method\n");
+ printDepth--;
+ writeIDNoSize(CJVMTI_LOCAL_NATIVECALL, variableFile);
+ return 0;
+ }
+ writeIDNoSize(CJVMTI_LOCAL_VARIABLE, variableFile);
+ fwrite(&loc, sizeof(jlocation), 1, variableFile);
+
+ // Work out how many are currently available
+ for (i = 0; i < varCount; i++) {
+ if ((table[i].start_location <= loc) && ((table[i].start_location
+ + table[i].length) >= loc)) {
+ aliveVarCount++;
+ }
+ }
+
+ writeJint(aliveVarCount, variableFile);
+ refLoc = FTELL(variableFile);
+ for (i = 0; i < aliveVarCount; i++) {
+ writeJint(0, variableFile);
+ writeReference(waitingToBeWritten, variableFile);
+ }
+
+ // Follow the available slots and output data.
+ FSEEK(variableFile, refLoc, SEEK_SET);
+ for (i = 0; i < varCount; i++) {
+ if ((table[i].start_location <= loc) && ((table[i].start_location
+ + table[i].length) >= loc)) {
+ writeJint(table[i].slot, variableFile);
+ refLoc = FTELL(variableFile);
+ FSEEK(variableFile, 0, SEEK_END);
+ tempLoc = addFieldValue(CJVMTI_LOCAL_VAR, NULL, NULL,
+ table[i].signature, *thread, depth, table[i].slot);
+ FSEEK(variableFile, refLoc, SEEK_SET);
+ writeReference(tempLoc, variableFile);
+ (*env)->Deallocate(env, (unsigned char*)table[i].generic_signature);
+ (*env)->Deallocate(env, (unsigned char*)table[i].name);
+ (*env)->Deallocate(env, (unsigned char*)table[i].signature);
+ } else {
+ printfd("Not currently in slot, ignore\n");
+ }
+ }
+ (*env)->Deallocate(env, (unsigned char*)table);
+ printDepth--;
+ return 1;
+}
+
+FPOS_T getFrameInfo(int depth, jvmtiFrameInfo * info, jthread * thread) {
+ jvmtiError err;
+ jclass declClass;
+ FPOS_T dClassPos;
+ FPOS_T position;
+
+ char* methodName;
+ struct JClass * declClazz;
+ printDepth++;
+ err = (*env)->GetMethodName(env, info->method, &methodName, NULL, NULL);
+ err = (*env)->GetMethodDeclaringClass(env, info->method, &declClass);
+ if (err != JVMTI_ERROR_NONE) {
+ position = FTELL(variableFile);
+ writeIDNoSize(CJVMTI_JVMTI_ERROR, variableFile);
+ return position;
+ }
+ FSEEK(variableFile, 0, SEEK_END);
+ if (declClass != 0) {
+ declClazz = addClassDetails(declClass);
+ if (declClazz != NULL){
+ dClassPos = declClazz->positionInFile;}else
+ {
+ dClassPos = CJVMTI_NULL_OBJECT;
+ }
+ } else {
+ dClassPos = CJVMTI_NULL_OBJECT;
+ }
+ FSEEK(variableFile, 0, SEEK_END);
+ position = FTELL(variableFile);
+ writeIDNoSize(CJVMTI_FRAME, variableFile);
+ writeReference((FPOS_T) info->method, variableFile);
+ writeString(methodName, variableFile); // TODO not required
+ writeReference(dClassPos, variableFile);
+
+ getLocVars(info->method, info->location, thread, depth);
+ printDepth--;
+ (*env)->Deallocate(env, (unsigned char*)methodName);
+ return position;
+
+}
+
+FPOS_T getThreadInfo(jthread * thread) {
+ int i;
+ int maxDepth = 5;
+ jvmtiThreadInfo info;
+ jvmtiFrameInfo frames[5];
+ jvmtiError err;
+
+ jint ownedMonitorCount;
+ jobject * ownedObjects;
+
+ jobject contendedObject;
+ struct JObject * monObj;
+
+ jint frameCount;
+
+ FPOS_T position;
+ FPOS_T refLoc;
+ FPOS_T tempRef;
+
+ printDepth++;
+
+ err = (*env)->GetThreadInfo(env, *thread, &info);
+ if (err != JVMTI_ERROR_NONE) {
+ printf("No thread info %d \n ", err);
+ abort();
+ }
+ err = (*env)->GetCurrentContendedMonitor(env, *thread, &contendedObject);
+ if (err != JVMTI_ERROR_NONE) {
+ contendedObject = 0;
+ }
+ err = (*env)->GetOwnedMonitorInfo(env, *thread, &ownedMonitorCount,
+ &ownedObjects);
+ if (err != JVMTI_ERROR_NONE) {
+ ownedMonitorCount = 0;
+ }
+ err = (*env)->GetStackTrace(env, *thread, 0, maxDepth, frames, &frameCount);
+ if (err != JVMTI_ERROR_NONE) {
+ frameCount = 0;
+ }
+
+ position = FTELL(variableFile);
+ writeIDNoSize(CJVMTI_THREAD, variableFile);
+ writeString(info.name, variableFile);
+ writeReference(addObject(*thread)->positionInFile, variableFile);
+ writeJint(info.priority, variableFile);
+ writeBool(info.is_daemon, variableFile);
+ writeJint(ownedMonitorCount, variableFile);
+ refLoc = FTELL(variableFile);
+ for (i = 0; i < ownedMonitorCount; i++) {
+ writeReference(waitingToBeWritten, variableFile); // Owned monitor objects
+ }
+ writeReference(waitingToBeWritten, variableFile); // Contended object
+ writeIDNoSize(CJVMTI_FRAME, variableFile);
+ writeJint(frameCount, variableFile);
+ for (i = 0; i < frameCount; i++) {
+ writeReference(waitingToBeWritten, variableFile); // Stack frames
+ }
+
+ // Allocated space, fill references
+ FSEEK(variableFile, 0, SEEK_END);
+ for (i = 0; i < ownedMonitorCount; i++) {
+ monObj = addObject(ownedObjects[i]);
+ FSEEK(variableFile, refLoc, SEEK_SET);
+ writeReference(monObj->positionInFile, variableFile);
+ refLoc = FTELL(variableFile);
+ FSEEK(variableFile, 0, SEEK_END);
+ }
+ (*env)->Deallocate(env, (unsigned char*)ownedObjects);
+ ownedObjects = NULL;
+ if (contendedObject != 0) {
+ monObj = addObject(contendedObject);
+ FSEEK(variableFile, refLoc, SEEK_SET);
+ writeReference(monObj->positionInFile, variableFile);
+ } else {
+ FSEEK(variableFile, refLoc, SEEK_SET);
+ writeReference(CJVMTI_NULL_OBJECT, variableFile);
+ }
+ writeIDNoSize(CJVMTI_FRAME, variableFile);
+ writeJint(frameCount, variableFile);
+ refLoc = FTELL(variableFile);
+ FSEEK(variableFile, 0, SEEK_END);
+ for (i = 0; i < frameCount; i++) {
+ tempRef = getFrameInfo(i, &frames[i], thread);
+ FSEEK(variableFile, refLoc, SEEK_SET);
+ writeReference(tempRef, variableFile);
+ refLoc = FTELL(variableFile);
+ FSEEK(variableFile, 0, SEEK_END);
+ }
+
+ return position;
+}
+
+int followAllThreads() {
+ jvmtiError err;
+ jint threadCount;
+ jthread * threads;
+ FPOS_T refLoc;
+ FPOS_T ref;
+ FPOS_T check;
+ int i;
+
+ err = (*env)->GetAllThreads(env, &threadCount, &threads);
+ writeIDNoSize(CJVMTI_THREAD, variableFile);
+ writeJint(threadCount, variableFile);
+ refLoc = FTELL(variableFile);
+ for (i = 0; i < threadCount; i++) {
+ writeReference(waitingToBeWritten, variableFile); // Prepare reference space in file
+ }
+ check = FTELL(variableFile);
+ for (i = 0; i < threadCount; i++) {
+ clearObjectQueue();
+ addObject(threads[i]); // Add all thread objects
+ }
+ printf(" Q size %d \n", Q_size(qObjects));
+
+ FSEEK(variableFile, 0, SEEK_END);
+ for (i = 0; i < threadCount; i++) {
+ ref = getThreadInfo(&threads[i]);
+ FSEEK(variableFile, refLoc, SEEK_SET);
+ writeReference(ref, variableFile);
+ refLoc = FTELL(variableFile);
+ FSEEK(variableFile, 0, SEEK_END);
+ }
+
+
+ clearObjectQueue();
+ (*env)->Deallocate(env, (unsigned char*)threads);
+ printfd("--- Finished following threads ---\n");
+ return 1;
+}
Added: incubator/kato/trunk/org.apache.kato/kato.native/kato.native.cjvmti/src/main/native/cjvmti.c
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/org.apache.kato/kato.native/kato.native.cjvmti/src/main/native/cjvmti.c?rev=812050&view=auto
==============================================================================
--- incubator/kato/trunk/org.apache.kato/kato.native/kato.native.cjvmti/src/main/native/cjvmti.c (added)
+++ incubator/kato/trunk/org.apache.kato/kato.native/kato.native.cjvmti/src/main/native/cjvmti.c Mon Sep 7 09:20:52 2009
@@ -0,0 +1,363 @@
+/*******************************************************************************
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ ******************************************************************************/
+
+
+#include "cjvmti.h"
+#include "addThreads.h"
+#include "addField.h"
+#include "addClass.h"
+#include "addObject.h"
+
+
+static int logFile = 0;
+int initAgent();
+
+// Provides printing to log/stdout
+void printfR(const char * _Format, ...) {
+ va_list args;
+ va_start(args, _Format);
+ assert(printDepth > -1);
+ //vprintf(_Format, args);
+
+ va_end(args);
+ va_start(args, _Format);
+ if (logFile) {
+ //vfprintf(fp, _Format, args);
+ }
+ va_end(args);
+}
+
+// Provides printing to log/stdout
+void printfd(const char * _Format, ...) {
+ int i;
+ va_list args;
+ va_start(args, _Format);
+ assert(printDepth > -1);
+
+ for (i = 0; i < printDepth; i++) {
+ //printf(" ");
+ if (logFile) {
+ //fprintf(fp, " ");
+ }
+ }
+ //vprintf(_Format, args);
+
+ va_end(args);
+ va_start(args, _Format);
+ if (logFile) {
+ //vfprintf(fp, _Format, args);
+ }
+ va_end(args);
+}
+
+int writeIDNoSize(char id, FILE * fp) {
+ fwrite(&id, sizeof(char), 1, fp);
+ return 1;
+}
+
+// Write a CJVMTI constant and make space to write the size of the following structure, returns the location in the file where the size needs to be written
+FPOS_T writeID(char id, FILE * fp) {
+ FPOS_T pos;
+ FPOS_T ident = 0x8888888888888888LL;
+ fwrite(&id, sizeof(char), 1, fp);
+ pos = FTELL(fp);
+ fwrite(&ident, sizeof(FPOS_T), 1, fp);
+ return pos;
+}
+
+// Works out and writes the size of the enclosed structure, sizeWrite is the position to write the size into
+int writeSize(FPOS_T sizeWrite, FILE * fp) {
+ FPOS_T pos;
+ FGETPOS(fp, &pos);
+ FSETPOS(fp, &sizeWrite);
+ sizeWrite = pos - sizeWrite;
+ fwrite(&sizeWrite, sizeof(FPOS_T), 1, fp);
+ FSEEK(fp, 0, SEEK_END);
+ return 1;
+}
+
+// Writes a null terminated string, needs replacing
+int writeString(char * tString, FILE * fp) {
+ fputs(tString, fp);
+ fputc(0, fp);
+ return 1;
+}
+
+int writeJint(jint i, FILE * fp) {
+ fwrite(&i, sizeof(jint), 1, fp);
+ return 1;
+}
+
+// Used for writing longs and file position, needs splitting up
+int writeReference(FPOS_T pt, FILE * fp) {
+ //if (pt == waitingToBeWritten) {
+ // abort();
+ //}
+ fwrite(&pt, sizeof(FPOS_T), 1, fp);
+ return 1;
+}
+
+int writeLong(jlong j, FILE *fp) {
+ fwrite(&j, sizeof(jlong), 1, fp);
+ return 1;
+}
+
+int writeBool(jboolean b, FILE * fp) {
+ fwrite(&b, sizeof(char), 1, fp);
+ return 1;
+}
+
+
+int clearObjectQueue() {
+ jclass clazz;
+ jobject obj;
+ obj = 0;
+ clazz = 0;
+ while (Q_dequeue(&obj, qObjects) != 0 || Q_dequeue(&clazz, qStaticFields) != 0) {
+ if (obj != 0){
+ getObjectReferences(obj);
+ }
+ if(clazz != 0){
+ addStaticFields(clazz);
+ }
+ }
+ return 1;
+}
+
+// Ensures references are within range, useful for testing
+int checkReference(FPOS_T loc, FILE * fp) {
+ FPOS_T fileSize;
+ FPOS_T currentLoc = FTELL(fp);
+ FSEEK(fp, 0, SEEK_END);
+ fileSize = FTELL(fp);
+ if (loc > fileSize + 1) {
+ printf("File size %lld \n", fileSize);
+ printf("Bad reference! %lld \n", loc);
+ abort();
+ return 0;
+ }
+ FSETPOS(fp, ¤tLoc);
+ return 1;
+}
+
+static void dump() {
+ printf("Finished writing dump file \n");
+}
+
+static void JNICALL dataDumpRequest(jvmtiEnv *jvmti) {
+ int i;
+ jint rc;
+ jthread currentThread;
+ jlong tag;
+ jobject deTagObj;
+ struct JObject * deAlObj;
+ struct JClass * deAlClass;
+ jthread * suspendedThreads;
+ jint numSuspendedThreads;
+ env = jvmti;
+ rc = (*vmptr)->GetEnv(vmptr, (void **) &jniptr, JNI_VERSION_1_6);
+ if (rc != JVMTI_ERROR_NONE) {
+ printf("Unable to load JNI environment");
+ return;
+ }
+ nullObject.positionInFile = CJVMTI_NULL_OBJECT;
+ initAgent();
+
+ (*jvmti)->GetCurrentThread(jvmti, ¤tThread);
+
+
+ (*env)->SetTag(env, currentThread, 1);
+ rc = (*env)->GetAllThreads(env, &numSuspendedThreads, &suspendedThreads);
+ printf("Suspend the VM threads \n");
+ printf("Current thread is %llx \n", currentThread);
+ for (i = 0; i < numSuspendedThreads; i++) {
+ (*env)->GetTag(env, suspendedThreads[i], &tag);
+ if (tag == 0) {
+ (*env)->SuspendThread(env, suspendedThreads[i]);
+ } else {
+ (*env)->SetTag(env, suspendedThreads[i], 0);
+ }
+ }
+ (*env)->SetTag(env,currentThread, 0);
+ printf("Creating dump file \n");
+
+ qObjects = Q_initQueue(100, sizeof(jobject));
+ qStaticFields = Q_initQueue(100, sizeof(jclass));
+ toDetag = Q_initQueue(200, sizeof(jobject));
+
+ followAllThreads();
+ if (fp!=NULL)fclose(fp);
+ fp = NULL;
+ fclose(variableFile);
+
+ printf("Detag/deallocate\n");
+ while (Q_dequeue(&deTagObj, toDetag)!= 0){
+ (*env)->GetTag(env, deTagObj, &tag);
+ if (tag == 0)continue; // We sometimes free an object from earlier in the queue if it went from an object to a class object
+ deAlObj = (struct JObject *)tag;
+ if (deAlObj->isClass){
+ // TODO isClass is set before add object
+ deAlClass = (struct JClass *) tag;
+
+ for (i = 0; i < deAlClass->numInstanceFields; i++){
+ (*env)->Deallocate(env, (unsigned char*)deAlClass->instanceFieldGenSig[i]);
+ (*env)->Deallocate(env, (unsigned char*)deAlClass->instanceFieldSignatures[i]);
+ }
+ (*env)->Deallocate(env, (unsigned char*)deAlClass->name);
+ free(deAlClass->instanceFieldGenSig);
+ free(deAlClass->instanceFields);
+ free(deAlClass->instanceFieldSignatures);
+ free(deAlClass->instanceModifiers);
+ free(deAlClass->staticFieldLoc);
+
+
+ }
+ free((void*)tag);
+ (*env)->SetTag(env, deTagObj, 0);
+ }
+
+ printf("Resume threads \n");
+ for (i = 0; i < numSuspendedThreads; i++) {
+ (*env)->ResumeThread(env, suspendedThreads[i]);
+ }
+
+ Q_free(toDetag);
+ Q_free(qObjects);
+ Q_free(qStaticFields);
+
+ (*env)->Deallocate(env, (unsigned char *)suspendedThreads);
+ printf("Left over object %d \n", objectCount);
+ printf("Left over static fields %d \n", staticsCount);
+ printf("Finished creating dump file \n");
+}
+
+int initAgent(){
+ static int dumpCount;
+
+ time_t creationTime;
+ struct tm * dumpTime;
+ char fileName[50];
+ int nameType = 0; // Switches between timestamping the file and not
+ int endianCheck = 1;
+ objectCount = 0;
+ staticsCount = 0;
+ printDepth = 0;
+ logFile = 0;
+#ifdef __DEBUG_CJVMTI__
+ _CrtDumpMemoryLeaks();
+#endif
+ if (logFile) {
+ printf("Open log file\n");
+ fp = fopen("CJVMTI_debug.txt", "wb+");
+ fprintf(fp, "CJVMTI LOG FILE\n");
+ printf("Opened\n");
+ }
+
+ printf("Creating dump file ");
+ creationTime = time(NULL);
+ dumpTime = localtime(&creationTime);
+ if (nameType){
+ sprintf(fileName, "cjvmti%04d.%02d.%02d.%02d%02d.%02d.cdmp", 1900+dumpTime->tm_year, 1+dumpTime->tm_mon, dumpTime->tm_mday, dumpTime->tm_hour, dumpTime->tm_min, dumpTime->tm_sec);
+ }else{
+ sprintf(fileName, "cjvmtiV%d.cdmp", dumpCount);
+ }
+ printf(fileName);
+ printf("\n");
+ variableFile = fopen(fileName, "wb+");
+
+ // print header info
+ writeReference(0, variableFile);
+ fwrite(&endianCheck, sizeof(int), 1, variableFile);
+ fprintf(variableFile, "CJVMTI V0.01");
+ fwrite(&creationTime, sizeof(time_t), 1, variableFile);
+ dumpCount++;
+ return 1;
+}
+
+JNIEXPORT jint JNICALL
+Agent_OnLoad(JavaVM *vm, char *options, void *reserved) {
+ jint rc;
+ jvmtiError err;
+ jvmtiCapabilities caps;
+ jvmtiEventCallbacks callbacks;
+
+
+ printf("CJVMTI v0.1 \n");
+
+ // print header info
+
+ vmptr = vm;
+ rc = (*vm)->GetEnv(vm, (void **) &env, JVMTI_VERSION);
+ if (rc != JVMTI_ERROR_NONE) {
+ printf("--- Cannot connect to JNI ---\n");
+ return rc;
+ }
+ memset(&callbacks, 0, sizeof(callbacks));
+ callbacks.DataDumpRequest = &dataDumpRequest;
+
+ err = (*env)->SetEventCallbacks(env, &callbacks, sizeof(callbacks));
+ if (err != JVMTI_ERROR_NONE)
+ printf("Could not set callbacks");
+
+
+ err = (*env)->SetEventNotificationMode(env, JVMTI_ENABLE,
+ JVMTI_EVENT_DATA_DUMP_REQUEST, (jthread) NULL);
+ if (err != JVMTI_ERROR_NONE)
+ printf("Could not set event notification");
+
+ memset(&caps, 0, sizeof(jvmtiCapabilities));
+
+ caps.can_get_owned_monitor_info = 1;
+ caps.can_get_current_contended_monitor = 1;
+ caps.can_get_monitor_info = 1;
+ caps.can_access_local_variables = 1;
+ caps.can_tag_objects = 1;
+ caps.can_generate_exception_events = 1;
+ caps.can_get_source_file_name = 1;
+ caps.can_get_line_numbers = 1;
+ caps.can_signal_thread = 1;
+ caps.can_suspend = 1;
+
+ err = (*env)->AddCapabilities(env, &caps);
+ if (err != JVMTI_ERROR_NONE)
+ printf("can't turn on required capabilites\n");
+
+ err = (*env)->CreateRawMonitor(env, "cbmonitor", &lock);
+ if (err != JVMTI_ERROR_NONE)
+ printf("cannot create monitor");
+ fp = NULL;
+ variableFile = NULL;
+#ifdef __DEBUG_CJVMTI__
+ hLogFile = CreateFile("c:\\memLeakCJVMTI.txt", GENERIC_WRITE,
+ FILE_SHARE_WRITE, NULL, CREATE_ALWAYS,
+ FILE_ATTRIBUTE_NORMAL, NULL);
+ _CrtSetReportMode(_CRT_WARN, _CRTDBG_MODE_FILE);
+ _CrtSetReportFile(_CRT_WARN, hLogFile);
+
+ printf("Memory leak \n");
+ _CrtSetDbgFlag ( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF);
+ _CrtDumpMemoryLeaks();
+#endif
+ return JNI_OK;
+}
+
+JNIEXPORT void JNICALL
+Agent_OnUnload(JavaVM *vm) {
+#ifdef __DEBUG_CJVMTI__
+ _RPT0(_CRT_WARN,"file message\n");
+ CloseHandle(hLogFile);
+#endif
+ if (fp != NULL) fclose(fp);
+ if (fp != NULL) fclose(variableFile);
+}
Added: incubator/kato/trunk/org.apache.kato/kato.native/kato.native.cjvmti/src/main/native/include/addClass.h
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/org.apache.kato/kato.native/kato.native.cjvmti/src/main/native/include/addClass.h?rev=812050&view=auto
==============================================================================
--- incubator/kato/trunk/org.apache.kato/kato.native/kato.native.cjvmti/src/main/native/include/addClass.h (added)
+++ incubator/kato/trunk/org.apache.kato/kato.native/kato.native.cjvmti/src/main/native/include/addClass.h Mon Sep 7 09:20:52 2009
@@ -0,0 +1,22 @@
+/*******************************************************************************
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ ******************************************************************************/
+
+
+#ifndef addClass_H_
+#define addClass_H_
+#include "cjvmti.h"
+struct JClass * addClassDetails(jclass class);
+struct JClass * addStaticFields(jclass class);
+int addMethodDetails(jclass class);
+#endif
Added: incubator/kato/trunk/org.apache.kato/kato.native/kato.native.cjvmti/src/main/native/include/addField.h
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/org.apache.kato/kato.native/kato.native.cjvmti/src/main/native/include/addField.h?rev=812050&view=auto
==============================================================================
--- incubator/kato/trunk/org.apache.kato/kato.native/kato.native.cjvmti/src/main/native/include/addField.h (added)
+++ incubator/kato/trunk/org.apache.kato/kato.native/kato.native.cjvmti/src/main/native/include/addField.h Mon Sep 7 09:20:52 2009
@@ -0,0 +1,21 @@
+/*******************************************************************************
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ ******************************************************************************/
+
+
+#ifndef addField_H_
+#define addField_H_
+#include "cjvmti.h"
+FPOS_T addFieldValue(int type, jobject obj, jfieldID field, char * signature,
+ jthread thread, jint depth, jint slot);
+#endif
Added: incubator/kato/trunk/org.apache.kato/kato.native/kato.native.cjvmti/src/main/native/include/addObject.h
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/org.apache.kato/kato.native/kato.native.cjvmti/src/main/native/include/addObject.h?rev=812050&view=auto
==============================================================================
--- incubator/kato/trunk/org.apache.kato/kato.native/kato.native.cjvmti/src/main/native/include/addObject.h (added)
+++ incubator/kato/trunk/org.apache.kato/kato.native/kato.native.cjvmti/src/main/native/include/addObject.h Mon Sep 7 09:20:52 2009
@@ -0,0 +1,22 @@
+/*******************************************************************************
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ ******************************************************************************/
+
+
+#ifndef addObject_H_
+#define addObject_H_
+#include "cjvmti.h"
+struct JObject * addObject(jobject obj);
+struct JObject * getObjectInfo(jclass class, jobject obj);
+struct JObject * getObjectReferences(jobject obj);
+#endif
Added: incubator/kato/trunk/org.apache.kato/kato.native/kato.native.cjvmti/src/main/native/include/addThreads.h
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/org.apache.kato/kato.native/kato.native.cjvmti/src/main/native/include/addThreads.h?rev=812050&view=auto
==============================================================================
--- incubator/kato/trunk/org.apache.kato/kato.native/kato.native.cjvmti/src/main/native/include/addThreads.h (added)
+++ incubator/kato/trunk/org.apache.kato/kato.native/kato.native.cjvmti/src/main/native/include/addThreads.h Mon Sep 7 09:20:52 2009
@@ -0,0 +1,23 @@
+/*******************************************************************************
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ ******************************************************************************/
+
+
+#ifndef addThreads_H_
+#define addThreads_H_
+#include "cjvmti.h"
+int getLocVars(jmethodID methodID, jlocation loc, jthread * thread, int depth);
+FPOS_T getFrameInfo(int depth, jvmtiFrameInfo * info, jthread * thread);
+FPOS_T getThreadInfo(jthread * thread);
+int followAllThreads();
+#endif
Added: incubator/kato/trunk/org.apache.kato/kato.native/kato.native.cjvmti/src/main/native/include/cjvmti.h
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/org.apache.kato/kato.native/kato.native.cjvmti/src/main/native/include/cjvmti.h?rev=812050&view=auto
==============================================================================
--- incubator/kato/trunk/org.apache.kato/kato.native/kato.native.cjvmti/src/main/native/include/cjvmti.h (added)
+++ incubator/kato/trunk/org.apache.kato/kato.native/kato.native.cjvmti/src/main/native/include/cjvmti.h Mon Sep 7 09:20:52 2009
@@ -0,0 +1,162 @@
+/*******************************************************************************
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ ******************************************************************************/
+
+#ifndef CJVMTI_H_
+#define CJVMTI_H_
+
+#ifdef __linux__
+#define _FILE_OFFSET_BITS 64
+#elif WIN32
+// Uncomment to detect memory leaks
+//#define __DEBUG_CJVMTI__
+#endif
+
+#ifdef __DEBUG_CJVMTI__
+#define _CRTDBG_MAP_ALLOC
+ #include <stdlib.h>
+ #include <crtdbg.h>
+#include <windows.h>
+#endif
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <assert.h>
+#include <time.h>
+#include <malloc.h>
+
+#ifdef __linux__
+#define FPOS_T off_t
+#define FSEEK(x,y,z) fseeko((x),(y),(z))
+#define FTELL(x) ftello((x))
+#define FGETPOS(x,y) (*(y))=ftello((x))
+#define FSETPOS(x,y) fseeko((x), (*(y)), SEEK_SET)
+#elif WIN32
+#define FPOS_T __int64
+#define FSEEK(x,y,z) _fseeki64((x),(y),(z))
+#define FTELL(x) _ftelli64((x))
+#define FGETPOS(x,y) (*(y))=_ftelli64((x))
+#define FSETPOS(x,y) _fseeki64((x), (*(y)), SEEK_SET)
+#endif
+
+#include "queue.h"
+#include "jvmti.h"
+
+struct JObject {
+ int state; // 0 not prepared 1 prepared 2 is references filled
+ FPOS_T positionInFile;
+ FPOS_T referenceLocation;
+ int totalFieldCount;
+ char isClass;
+};
+
+struct JClass {
+ struct JObject obj;
+ int filledIn;
+ char * name; // dealloc from jvmti
+ FPOS_T positionInFile;
+ FPOS_T classLoader;
+ FPOS_T staticFieldStart;
+ struct JClass * superClass;
+ int numStaticFields;
+ FPOS_T * staticFieldLoc;
+ int numInstanceFields;
+ jfieldID * instanceFields; //
+ char * * instanceFieldSignatures; // each ref is jvmti, malloced normally
+ char * * instanceFieldGenSig; // each ref is jvmti, malloced normally
+ jint * instanceModifiers; // malloced normally
+};
+
+#define CJVMTI_LOCAL_VAR 0
+#define CJVMTI_STATIC_VAR 1
+#define CJVMTI_INSTANCE_VAR 2
+#define CJVMTI_ARRAY_VAR 3
+// Field values
+#define CJVMTI_BYTE 0x1c
+#define CJVMTI_CHAR 0x01
+#define CJVMTI_DOUBLE 0x02
+#define CJVMTI_FLOAT 0x03
+#define CJVMTI_INT 0x04
+#define CJVMTI_LONG 0x05
+#define CJVMTI_OBJECT 0x06
+#define CJVMTI_SHORT 0x07
+#define CJVMTI_BOOLEAN 0x08
+// Field arrays
+#define CJVMTI_OBJECTARRAY 0x09
+#define CJVMTI_BYTE_ARRAY 0x0a
+#define CJVMTI_CHAR_ARRAY 0x0b
+#define CJVMTI_DOUBLE_ARRAY 0x0c
+#define CJVMTI_FLOAT_ARRAY 0x0d
+#define CJVMTI_INT_ARRAY 0x0e
+#define CJVMTI_LONG_ARRAY 0x0f
+#define CJVMTI_OBJECT_ARRAY 0x10
+#define CJVMTI_SHORT_ARRAY 0x11
+#define CJVMTI_BOOLEAN_ARRAY 0x12
+// Structure ID's
+#define CJVMTI_METHOD 0x13
+#define CJVMTI_THREAD_GROUP 0x14
+#define CJVMTI_THREAD 0x15
+#define CJVMTI_FRAME 0x16
+#define CJVMTI_FIELD_MODIFIERS 0x17
+#define CJVMTI_MONITORS 0x18
+#define CJVMTI_CLASSLOADERS 0x19
+// General error's and extra additions
+#define CJVMTI_LOCAL_NATIVECALL 0x1a
+#define CJVMTI_CLASS 0x1b
+#define CJVMTI_NULL_OBJECT 0x00
+#define CJVMTI_CLASS_INSTANCE_FIELDS 0x1d
+#define CJVMTI_CLASS_STATIC_FIELDS 0x1e
+#define CJVMTI_CLASS_FIELDS 0x1f
+#define CJVMTI_NULL_OBJECT_ARRAY 0x00
+#define CJVMTI_LOCAL_VARIABLE 0x20
+#define CJVMTI_JVMTI_ERROR 0x21
+#define CJVMTI_STRING 0x22;
+#define CJVMTI_SUPERCLASS_FIELDS 0x23
+#define CJVMTI_CLASS_INTERFACES 0x24
+
+
+// Global variables
+jvmtiEnv *env;
+JavaVM *vmptr;
+JNIEnv *jniptr;
+jrawMonitorID lock;
+FILE *fp;
+FILE *variableFile;
+int printDepth;
+struct queueADT * qObjects;
+struct queueADT * qStaticFields;
+struct queueADT * toDetag; // JObjects that need to be detagged and freed
+long objectCount;
+long staticsCount;
+struct JObject nullObject;
+#ifdef __DEBUG_CJVMTI__
+HANDLE hLogFile;
+#endif
+// End globals
+
+
+
+static FPOS_T waitingToBeWritten = 0x9999999999999999LL; // Used to find unwritten references in output files, should not occur
+int clearObjectQueue(); // Clear references to objects made by other objects so far.
+void printfR(const char * _Format, ...);
+void printfd(const char * _Format, ...);
+int writeIDNoSize(char id, FILE * fp);
+FPOS_T writeID(char id, FILE * fp) ;
+int writeSize(FPOS_T sizeWrite, FILE * fp);
+int writeString(char * tString, FILE * fp);
+int writeJint(jint i, FILE * fp);
+int writeReference(FPOS_T pt, FILE * fp);
+int writeLong(jlong j, FILE *fp);
+int writeBool(jboolean b, FILE * fp);
+#endif