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 mo...@apache.org on 2009/11/27 17:10:18 UTC
svn commit: r884911 - in
/incubator/kato/trunk/org.apache.kato/kato.cjvmti/src/main/java/org/apache/kato/jvmti:
javaruntime/model/JClassLoader.java javaruntime/model/Model.java
reader/CJVMTIBinReader.java
Author: monteith
Date: Fri Nov 27 17:10:18 2009
New Revision: 884911
URL: http://svn.apache.org/viewvc?rev=884911&view=rev
Log:
Add support for new ClassLoader records.
Modified:
incubator/kato/trunk/org.apache.kato/kato.cjvmti/src/main/java/org/apache/kato/jvmti/javaruntime/model/JClassLoader.java
incubator/kato/trunk/org.apache.kato/kato.cjvmti/src/main/java/org/apache/kato/jvmti/javaruntime/model/Model.java
incubator/kato/trunk/org.apache.kato/kato.cjvmti/src/main/java/org/apache/kato/jvmti/reader/CJVMTIBinReader.java
Modified: incubator/kato/trunk/org.apache.kato/kato.cjvmti/src/main/java/org/apache/kato/jvmti/javaruntime/model/JClassLoader.java
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/org.apache.kato/kato.cjvmti/src/main/java/org/apache/kato/jvmti/javaruntime/model/JClassLoader.java?rev=884911&r1=884910&r2=884911&view=diff
==============================================================================
--- incubator/kato/trunk/org.apache.kato/kato.cjvmti/src/main/java/org/apache/kato/jvmti/javaruntime/model/JClassLoader.java (original)
+++ incubator/kato/trunk/org.apache.kato/kato.cjvmti/src/main/java/org/apache/kato/jvmti/javaruntime/model/JClassLoader.java Fri Nov 27 17:10:18 2009
@@ -14,7 +14,6 @@
package org.apache.kato.jvmti.javaruntime.model;
-import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
@@ -25,32 +24,40 @@
public class JClassLoader implements JavaClassLoader {
- private List<JavaClass> classes=null;
+ private List<JavaClass> cachedClasses=null;
+ private List<JavaClass> definedClasses = null;
public JObject obj = null;
@Override
public JavaClass findClass(String name) throws CorruptDataException {
- for (JavaClass c: classes){
+ for (JavaClass c: cachedClasses){
if (c.getName().equals(name))return c;
}
return null;
}
public void addClass(JClass c) {
- if(classes==null) classes=new LinkedList<JavaClass>();
- classes.add(c);
- c.classloader = this;
+ if(cachedClasses==null) cachedClasses=new LinkedList<JavaClass>();
+ if(definedClasses==null) definedClasses=new LinkedList<JavaClass>();
+
+ cachedClasses.add(c);
+
+ // If this class is defined by this loader, store it here.
+ if (c.classloader == this) {
+ definedClasses.add(c);
+ }
}
@Override
public List<JavaClass> getCachedClasses() {
- return Collections.emptyList();
+ if(cachedClasses==null) cachedClasses=new LinkedList<JavaClass>();
+ return cachedClasses;
}
@Override
public List<JavaClass> getDefinedClasses() {
- if(classes==null) classes=new LinkedList<JavaClass>();
- return classes;
+ if(definedClasses==null) definedClasses=new LinkedList<JavaClass>();
+ return definedClasses;
}
@Override
Modified: incubator/kato/trunk/org.apache.kato/kato.cjvmti/src/main/java/org/apache/kato/jvmti/javaruntime/model/Model.java
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/org.apache.kato/kato.cjvmti/src/main/java/org/apache/kato/jvmti/javaruntime/model/Model.java?rev=884911&r1=884910&r2=884911&view=diff
==============================================================================
--- incubator/kato/trunk/org.apache.kato/kato.cjvmti/src/main/java/org/apache/kato/jvmti/javaruntime/model/Model.java (original)
+++ incubator/kato/trunk/org.apache.kato/kato.cjvmti/src/main/java/org/apache/kato/jvmti/javaruntime/model/Model.java Fri Nov 27 17:10:18 2009
@@ -36,6 +36,9 @@
private ObjectMapList<Long,JavaMethod> methodMap=new ObjectMapList<Long,JavaMethod>();
private ObjectMapList<Long,JavaObject> objectMap=new ObjectMapList<Long,JavaObject>();
+ // Exists so that artificial classes can be added before actual system loaders is read.
+ private JClassLoader systemClassLoader = new JClassLoader();
+
public JClass getClass(long id) {
if(id==0) return null;
JClass m=(JClass) classMap.get(id);
@@ -64,12 +67,8 @@
}
public JClassLoader getLoader(long classloaderid) {
-
JClassLoader loader=(JClassLoader) loadersMap.get(classloaderid);
- if(loader==null) {
- loader=new JClassLoader();
- loadersMap.put(classloaderid, loader);
- }
+
return loader;
}
@@ -148,4 +147,17 @@
return heap;
}
+ /**
+ * Store a new classloader.
+ *
+ * @param position its position in the file
+ * @param classLoader Its object
+ */
+ public void putLoader(long position, JavaClassLoader classLoader) {
+ this.loadersMap.put(position, classLoader);
+ }
+
+ public JClassLoader getSystemClassLoader() {
+ return systemClassLoader;
+ }
}
Modified: incubator/kato/trunk/org.apache.kato/kato.cjvmti/src/main/java/org/apache/kato/jvmti/reader/CJVMTIBinReader.java
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/org.apache.kato/kato.cjvmti/src/main/java/org/apache/kato/jvmti/reader/CJVMTIBinReader.java?rev=884911&r1=884910&r2=884911&view=diff
==============================================================================
--- incubator/kato/trunk/org.apache.kato/kato.cjvmti/src/main/java/org/apache/kato/jvmti/reader/CJVMTIBinReader.java (original)
+++ incubator/kato/trunk/org.apache.kato/kato.cjvmti/src/main/java/org/apache/kato/jvmti/reader/CJVMTIBinReader.java Fri Nov 27 17:10:18 2009
@@ -59,42 +59,43 @@
// This is literally the String in the dump file. Also reported by JavaRuntime
public static final String CJVMTI_VERSION_STRING = "CJVMTI V0.01";
- private static final byte CJVMTI_BYTE = 0x1c;
- private static final byte CJVMTI_CHAR = 0x01;
- private static final byte CJVMTI_DOUBLE = 0x02;
- private static final byte CJVMTI_FLOAT = 0x03;
- private static final byte CJVMTI_INT = 0x04;
- private static final byte CJVMTI_LONG = 0x05;
- private static final byte CJVMTI_OBJECT = 0x06;
- private static final byte CJVMTI_SHORT = 0x07;
- private static final byte CJVMTI_BOOLEAN = 0x08;
- private static final byte CJVMTI_OBJECTARRAY = 0x09;
- private static final byte CJVMTI_BYTE_ARRAY = 0x0a;
- private static final byte CJVMTI_CHAR_ARRAY = 0x0b;
- private static final byte CJVMTI_DOUBLE_ARRAY = 0x0c;
- private static final byte CJVMTI_FLOAT_ARRAY = 0x0d;
- private static final byte CJVMTI_INT_ARRAY = 0x0e;
- private static final byte CJVMTI_LONG_ARRAY = 0x0f;
- private static final byte CJVMTI_OBJECT_ARRAY = 0x10;
- private static final byte CJVMTI_SHORT_ARRAY = 0x11;
- private static final byte CJVMTI_BOOLEAN_ARRAY = 0x12;
- private static final byte CJVMTI_METHOD = 0x13;
- private static final byte CJVMTI_THREAD_GROUP = 0x14;
- private static final byte CJVMTI_THREAD = 0x15;
- private static final byte CJVMTI_FRAME = 0x16;
- private static final byte CJVMTI_FIELD_MODIFIERS = 0x17;
- private static final byte CJVMTI_MONITORS = 0x18;
- private static final byte CJVMTI_CLASSLOADERS = 0x19;
- private static final byte CJVMTI_LOCAL_NATIVECALL = 0x1a;
- private static final byte CJVMTI_CLASS = 0x1b;
+ private static final byte CJVMTI_BYTE = 0x01;
+ private static final byte CJVMTI_CHAR = 0x02;
+ private static final byte CJVMTI_DOUBLE = 0x03;
+ private static final byte CJVMTI_FLOAT = 0x04;
+ private static final byte CJVMTI_INT = 0x05;
+ private static final byte CJVMTI_LONG = 0x06;
+ private static final byte CJVMTI_OBJECT = 0x07;
+ private static final byte CJVMTI_SHORT = 0x08;
+ private static final byte CJVMTI_BOOLEAN = 0x09;
+ private static final byte CJVMTI_OBJECTARRAY = 0x0a;
+ private static final byte CJVMTI_BYTE_ARRAY = 0x0b;
+ private static final byte CJVMTI_CHAR_ARRAY = 0x0c;
+ private static final byte CJVMTI_DOUBLE_ARRAY = 0x0d;
+ private static final byte CJVMTI_FLOAT_ARRAY = 0x0e;
+ private static final byte CJVMTI_INT_ARRAY = 0x0f;
+ private static final byte CJVMTI_LONG_ARRAY = 0x10;
+ private static final byte CJVMTI_OBJECT_ARRAY = 0x11;
+ private static final byte CJVMTI_SHORT_ARRAY = 0x12;
+ private static final byte CJVMTI_BOOLEAN_ARRAY = 0x13;
+ private static final byte CJVMTI_METHOD = 0x14;
+ private static final byte CJVMTI_THREAD_GROUP = 0x15;
+ private static final byte CJVMTI_THREAD = 0x16;
+ private static final byte CJVMTI_FRAME = 0x17;
+ private static final byte CJVMTI_FIELD_MODIFIERS = 0x18;
+ private static final byte CJVMTI_MONITORS = 0x19;
+ private static final byte CJVMTI_CLASSLOADER = 0x1a;
+ private static final byte CJVMTI_CLASSLOADERS = 0x1b;
+ private static final byte CJVMTI_LOCAL_NATIVECALL = 0x1c;
+ private static final byte CJVMTI_CLASS = 0x1d;
private static final byte CJVMTI_NULL_OBJECT = 0x00;
- private static final byte CJVMTI_CLASS_INSTANCE_FIELDS = 0x1d;
- private static final byte CJVMTI_CLASS_STATIC_FIELDS = 0x1e;
- private static final byte CJVMTI_CLASS_FIELDS = 0x1f;
+ private static final byte CJVMTI_CLASS_INSTANCE_FIELDS = 0x1e;
+ private static final byte CJVMTI_CLASS_STATIC_FIELDS = 0x1f;
+ private static final byte CJVMTI_CLASS_FIELDS = 0x20;
private static final long CJVMTI_NULL_OBJECT_ARRAY = 0x00;
- private static final byte CJVMTI_LOCAL_VARIABLE = 0x20;
- private static final byte CJVMTI_JVMTI_ERROR = 0x21;
+ private static final byte CJVMTI_LOCAL_VARIABLE = 0x21;
+ private static final byte CJVMTI_JVMTI_ERROR = 0x22;
private static final byte CJVMTI_SUPERCLASS_FIELDS = 0x23;
private static final byte CJVMTI_CLASS_INTERFACES = 0x24;
private long selfGeneratedIDs;
@@ -510,23 +511,12 @@
c.addInterface(interfaceC);
}
- // Follow class loader reference
- if (classLoaderRef == 0) {
- bootJCL.addClass(c);
- c.classloader = bootJCL;
- // c.classloader = null;
- } else {
- JClassLoader jcl = model.getLoader(classLoaderRef);
- jcl.addClass(c);
- if (jcl.obj == null) {
- JObject classLoaderObj = nreadObject(classLoaderRef);
- jcl.obj = classLoaderObj;
- }
+ {
+ JClassLoader jcl = nreadClassLoader(classLoaderRef);
c.classloader = jcl;
try {
log.log(Level.FINEST, "Class loader : "
- + c.getClassLoader().getObject().getJavaClass()
- .getName() + " for " + c.getName());
+ + c.getClassLoader().getObject() + " for " + c.getName());
} catch (CorruptDataException e) {
// TODO Auto-generated catch block
e.printStackTrace();
@@ -537,6 +527,66 @@
}
/**
+ * Loads in a classloader.
+ * This contains an optional reference to an object, and references to all of the
+ * classes within.
+ *
+ * @param position position of CJVMTI_CLASSLOADER record.
+ * @return CClassLoader
+ * @throws IOException
+ */
+ private JClassLoader nreadClassLoader(long position) throws IOException {
+ JClassLoader jcl = model.getLoader(position);
+
+ // We've already processed this classloader.
+ if (jcl != null) {
+ return jcl;
+ }
+
+ // This is important - otherwise other classes might try and load this.
+
+
+ variablesIn.seek(position);
+ short tag = variablesIn.readByte();
+ if (tag != CJVMTI_CLASSLOADER) {
+ throw new IOException("Missing CJVMTI_CLASSLOADER tag, got "+tag);
+ }
+
+ long loaderObject = variablesIn.readLong();
+ int classesCount = variablesIn.readInt();
+
+ // Reuse preexisiting system class laoder if this is what we are.
+ // This is necessary for artificially generated types.
+ if (loaderObject == CJVMTI_NULL_OBJECT) {
+ jcl = model.getSystemClassLoader();
+ } else {
+ jcl = new JClassLoader();
+ }
+ // Store loader.
+ model.putLoader(position, jcl );
+
+ // Read array of class references.
+ // This avoids seeking even more than we do already.
+ long[] classesRef = new long[classesCount];
+ for (int i=0; i < classesCount; i++) {
+ classesRef[i] = variablesIn.readLong();
+ }
+
+ jcl.obj = nreadObject(loaderObject);
+
+ // add all of the classes loaded by this classloader.
+ for (int i=0; i < classesCount; i++) {
+ long classPos = classesRef[i];
+
+ if (classPos != CJVMTI_NULL_OBJECT) {
+ jcl.addClass(nreadClass(classPos));
+ }
+ }
+
+ return jcl;
+ }
+
+ /**
* Conveniance class for loading objects
* @param position Position in file
* @return Populated JObject or null
@@ -829,7 +879,7 @@
// generate system classloader
selfGeneratedIDs++;
- bootJCL = model.getLoader(selfGeneratedIDs);
+ bootJCL = (JClassLoader) model.getSystemClassLoader();
JClass bootCLC = model.getClass(selfGeneratedIDs);
bootCLC.classSig = "Ljava/lang/CJVMTISystemClassLoader;";
JObject bootObj = model.getObject(selfGeneratedIDs, selfGeneratedIDs);
@@ -942,7 +992,11 @@
loc.method = jm;
jsf.setLocation(loc);
- loc.filename = clazz.sourceFile;
+
+ // SRDM
+ if( clazz != null) {
+ loc.filename = clazz.sourceFile;
+ }
t.addStackFrame(jsf);
byte depth = variablesIn.readByte();