* @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;
}