incubator-kato-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From monte...@apache.org
Subject svn commit: r885519 - /incubator/kato/trunk/org.apache.kato/kato.cjvmti/src/main/java/org/apache/kato/jvmti/reader/CJVMTIBinReader.java
Date Mon, 30 Nov 2009 17:56:08 GMT
Author: monteith
Date: Mon Nov 30 17:56:07 2009
New Revision: 885519

URL: http://svn.apache.org/viewvc?rev=885519&view=rev
Log:
Read in strings as UTF-8. Fixes non iso8859-1 characters.

Modified:
    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/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=885519&r1=885518&r2=885519&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
Mon Nov 30 17:56:07 2009
@@ -281,9 +281,9 @@
 	private JLocalVariableTableEntry nlocalVarTable()
 	throws IOException {
 		// log.log(Level.FINEST,"Get local var table");
-		String name = readCString(variablesIn);
-		String sig = readCString(variablesIn);
-		String genSig = readCString(variablesIn);
+		String name = readUTFString(variablesIn);
+		String sig = readUTFString(variablesIn);
+		String genSig = readUTFString(variablesIn);
 		int length = variablesIn.readInt();
 		int slot = variablesIn.readInt();
 		long start_location = variablesIn.readLong();
@@ -307,9 +307,9 @@
 		if (variablesIn.readByte() != CJVMTI_METHOD)
 			throw new IOException();
 		long methodID = variablesIn.readLong();
-		String mName = readCString(variablesIn);
-		String mSig = readCString(variablesIn);
-		String mGenSig = readCString(variablesIn);
+		String mName = readUTFString(variablesIn);
+		String mSig = readUTFString(variablesIn);
+		String mGenSig = readUTFString(variablesIn);
 		int modifiers = variablesIn.readInt();
 		int count = variablesIn.readInt();
 
@@ -349,9 +349,9 @@
 		for (int i = 0; i < fieldCount; i++) {
 			int modifiers = variablesIn.readInt();
 			long fieldID = variablesIn.readLong();
-			String name = readCString(variablesIn);
-			String sig = readCString(variablesIn);
-			String genSig = readCString(variablesIn);
+			String name = readUTFString(variablesIn);
+			String sig = readUTFString(variablesIn);
+			String genSig = readUTFString(variablesIn);
 			JField fl = c.getField(fieldID);
 			fl.name = name;
 			fl.genericsignature = genSig;
@@ -373,9 +373,9 @@
 		for (int i = 0; i < fieldCount; i++) {
 			int modifiers = variablesIn.readInt();
 			long fieldID = variablesIn.readLong();
-			String name = readCString(variablesIn);
-			String sig = readCString(variablesIn);
-			String genSig = readCString(variablesIn);
+			String name = readUTFString(variablesIn);
+			String sig = readUTFString(variablesIn);
+			String genSig = readUTFString(variablesIn);
 			JField fl = c.getField(fieldID);
 			fl.name = name;
 			fl.genericsignature = genSig;
@@ -393,13 +393,17 @@
 	 * @throws IOException
 	 */
 	private JClass nreadClass(long ref) throws IOException {
-		variablesIn.seek(ref);
-		if (ref == 0) {
+		if (ref == 0L) {
+			return null;
 		}
-		if (variablesIn.readByte() == CJVMTI_CLASS) {
+		
+		variablesIn.seek(ref);
+		
+		short tag = variablesIn.readByte();  
+		if (tag == CJVMTI_CLASS) {
 			return nreadClass();
 		} else {
-			log.log(Level.FINEST, "IO EX" + Long.toHexString(ref));
+			log.log(Level.FINEST, "nreadClass: incorrect tag"+tag+" at 0x" + Long.toHexString(ref));
 			throw new IOException("unable to read class at offset "+ref);
 		}
 	}
@@ -422,9 +426,9 @@
 		int modifiers = variablesIn.readInt();
 		c.modifiers = (short) modifiers;
 		log.log(Level.FINEST, "mods " + modifiers + " " + c.modifiers);
-		String name = readCString(variablesIn);
-		String sourceFile = readCString(variablesIn);
-		String genSig = readCString(variablesIn);
+		String name = readUTFString(variablesIn);
+		String sourceFile = readUTFString(variablesIn);
+		String genSig = readUTFString(variablesIn);
 
 		// TODO move this to C implementation
 		if (sourceFile.equals("NoSource")) {
@@ -957,7 +961,34 @@
 		return sb.toString();
 	}
 
-
+	/**
+	 * Read a UTF8 style null terminated string
+	 * @param z Input stream pointing at the start of the string
+	 * @return a String
+	 * @throws IOException
+	 */
+	private String readUTFString(FileImageInputStream z) throws IOException {
+		
+		z.mark();
+		
+		// Determine array size
+		int len = 0;
+		int cur;
+		while ((cur =  z.readUnsignedByte()) != 0) {
+			len++;
+		}
+		
+		// then read it into byte array
+		z.reset();
+		byte array[] = new byte[len];
+		int cnt = 0;
+		while ((cur =  z.readUnsignedByte()) != 0) {
+			array[cnt++] = (byte)cur;
+		}
+		
+		// Convert bytes into unicode string.
+		return new String(array,"UTF-8");
+	}
 
 	/**
 	 * Read a stack frame
@@ -979,7 +1010,7 @@
 		}
 
 		long methodID = variablesIn.readLong();
-		String methodName = readCString(variablesIn);
+		String methodName = readUTFString(variablesIn);
 		log.log(Level.FINEST, "Method name is: " + methodName);
 		long declaringClass = variablesIn.readLong();
 		long cPos = variablesIn.getStreamPosition(); // Save where we are before reading in the
declaring class
@@ -1111,7 +1142,7 @@
 			log.fine("Error");
 			System.exit(0);
 		}
-		String threadname = readCString(variablesIn);
+		String threadname = readUTFString(variablesIn);
 		log.finest("thread name "+threadname);
 
 		long objectRef = variablesIn.readLong();



Mime
View raw message