[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: glibj.zip with jikes rvm
> Feng Qian wrote:
> > >For example, gnu/java/lang/CharData.class(or
> > >java) in the glibj.zip has a couple of static string constant
> > >definitions, but newly converted CharData.class has just static string
> > >reference fields.
> > >
> > This is probably related to the bug we found a few days ago. Currently,
> > the ConstValue attribute of a static field was lost when a class is
> > converted to the soot internal representation. We had some discussion
> > before, but didnot decide a solution yet.
> >
> > The old mail thread about the bug:
> >
> > http://www.sable.mcgill.ca/listarchives/soot-list/msg01167.html
>
> I'm trying to understand this bug but amn't :-) Maybe I'm getting confused
> by the example given which has two classes.
>
> Is this the same bug I described a long time ago in this thread?
>
> http://www.sable.mcgill.ca/listarchives/soot-list/msg00495.html
>
> Or is more than one class actually required to see this bug?
>
> If it's the same bug (Soot dropping ConstantValue attributes), then it
> seems to me like Ondrej's solution is the obvious and correct one, i.e.,
> Don't Drop Them. It also seems like artificially inserting <clinit>
> code would be dangerous.
>
> Just my $0.02.
>
> -Archie
>
> __________________________________________________________________________
> Archie Cobbs * CTO, Awarix * http://www.awarix.com
I fixed the ConstantValue attributes bug even thou it doesn't seems to be fancy.
To do so, I modified jasmin as well.
To handle the special characters with string initialization(e.g, gnu/java/lang/CharData.java of gnu classpath),
when soot generate *.jasmin and jasmin read it,I used Base64 encoding.
The following are two patch files.
/* patch_jamin0303 */
diff -uNr src.old/jasmin/ClassFile.java src/jasmin/ClassFile.java
--- src.old/jasmin/ClassFile.java 2004-03-03 10:45:29.000000000 -0500
+++ src/jasmin/ClassFile.java 2004-03-03 10:49:08.000000000 -0500
@@ -22,6 +22,7 @@
import java.io.DataOutputStream;
import java.io.IOException;
import java.util.*;
+import java.io.*;
/**
* A ClassFile object is used to represent the binary data that makes up a
@@ -195,19 +196,28 @@
// create a constant pool entry for the initial value
CP cp = null;
-
// correctness patch due to Brian Demsky (bdemsky@mit.edu)
// it's strange that Soot doesn't trigger this bug.
if (sig.equals("I")||sig.equals("Z")||sig.equals("C")||sig.equals("B")||sig.equals("S")) {
- cp = new IntegerCP(((Number)value).intValue());
+ cp = new IntegerCP((new Integer(value.toString())).intValue());
} else if (sig.equals("F")) {
- cp = new FloatCP(((Number)value).floatValue());
- } else if (sig.equals("D")) {
- cp = new DoubleCP(((Number)value).doubleValue());
- } else if (sig.equals("L")) {
- cp = new LongCP(((Number)value).longValue());
+ cp = new FloatCP((new Float(value.toString())).floatValue());
+ } else if (sig.equals("D")) {
+ cp = new DoubleCP((new Double(value.toString())).doubleValue());
+ } else if (sig.equals("J")) {
+ cp = new LongCP((new Long(value.toString())).longValue());
} else if (sig.equals("Ljava/lang/String;")) {
- cp = new StringCP((String)value);
+ char[] charVal = value.toString().toCharArray();
+ byte[] utf8Val = Base64.decode(charVal);
+ String buf=null;
+ ByteArrayInputStream bs = new ByteArrayInputStream(utf8Val);
+ DataInputStream d = new DataInputStream(bs);
+ try{
+ buf = d.readUTF();
+ } catch(IOException e) {}
+ cp = new StringCP(buf);
+ } else {
+ System.out.println("[ClassFile Waring]: val="+value+", sig="+sig);
}
// add the field
/* patch_soot0303 */
diff -uNr src.old/soot/SootField.java src/soot/SootField.java
--- src.old/soot/SootField.java 2004-03-03 10:44:27.000000000 -0500
+++ src/soot/SootField.java 2004-03-03 11:02:04.000000000 -0500
@@ -24,6 +24,8 @@
*/
+/* Patched by kyungwoo Lee 2004/03/03 */
+
package soot;
import soot.tagkit.*;
@@ -40,6 +42,7 @@
String name;
Type type;
int modifiers;
+ public Object constValue;
boolean isDeclared = false;
SootClass declaringClass;
@@ -53,6 +56,16 @@
this.modifiers = modifiers;
if( type instanceof RefLikeType ) Scene.v().getFieldNumberer().add(this);
}
+
+ /** Constructs a Soot field with the given name, type, modifiers and constvalue */
+ public SootField(String name, Type type, int modifiers, Object constValue)
+ {
+ this.name = name;
+ this.type = type;
+ this.modifiers = modifiers;
+ this.constValue = constValue;
+ if( type instanceof RefLikeType ) Scene.v().getFieldNumberer().add(this);
+ }
/** Constructs a Soot field with the given name, type and no modifiers. */
public SootField(String name, Type type)
diff -uNr src.old/soot/baf/JasminClass.java src/soot/baf/JasminClass.java
--- src.old/soot/baf/JasminClass.java 2004-03-03 10:44:26.000000000 -0500
+++ src/soot/baf/JasminClass.java 2004-03-03 10:59:59.000000000 -0500
@@ -24,7 +24,7 @@
*/
-
+/* Patched by kyungwoo Lee 2004/03/03 */
package soot.baf;
@@ -275,9 +275,13 @@
while(fieldIt.hasNext())
{
SootField field = (SootField) fieldIt.next();
-
- emit(".field " + Modifier.toString(field.getModifiers()) + " " +
- "\"" + field.getName() + "\"" + " " + jasminDescriptorOf(field.getType()));
+
+ if(field.constValue==null)
+ emit(".field " + Modifier.toString(field.getModifiers()) + " " +
+ "\"" + field.getName() + "\"" + " " + jasminDescriptorOf(field.getType()));
+ else
+ emit(".field " + Modifier.toString(field.getModifiers()) + " " +
+ "\"" + field.getName() + "\"" + " " + jasminDescriptorOf(field.getType())+" = \""+field.constValue.toString()+"\"");
Iterator attributeIt = field.getTags().iterator();
diff -uNr src.old/soot/coffi/Util.java src/soot/coffi/Util.java
--- src.old/soot/coffi/Util.java 2004-03-03 10:44:27.000000000 -0500
+++ src/soot/coffi/Util.java 2004-03-03 10:59:34.000000000 -0500
@@ -24,8 +24,7 @@
*/
-
-
+/* Patched by kyungwoo Lee 2004/03/03 */
@@ -37,7 +36,7 @@
import java.io.*;
import soot.baf.*;
import soot.*;
-
+import soot.tagkit.*;
public class Util
{
@@ -406,10 +405,31 @@
int modifiers = fieldInfo.access_flags;
Type fieldType = jimpleTypeOfFieldDescriptor(cm, fieldDescriptor);
-
- bclass.addField(new SootField(fieldName,
- fieldType, modifiers));
-
+
+ ConstantValue_attribute ca = fieldInfo.findConstantValue_attribute();
+ if(ca==null) {
+ bclass.addField(new SootField(fieldName,
+ fieldType, modifiers));
+ } else {
+ Object constVal = coffiClass.constant_pool[ca.constantvalue_index];
+ if(constVal instanceof CONSTANT_Integer_info) {
+ constVal = new Integer((int) ((CONSTANT_Integer_info) constVal).bytes);
+ } else if(constVal instanceof CONSTANT_Float_info) {
+ constVal = new Float(((CONSTANT_Float_info) constVal).convert());
+ } else if(constVal instanceof CONSTANT_Double_info) {
+ constVal = new Double(((CONSTANT_Double_info) constVal).convert());
+ } else if(constVal instanceof CONSTANT_Long_info) {
+ constVal = new Long(((CONSTANT_Long_info) constVal).convert());
+ } else if(constVal instanceof CONSTANT_String_info) {
+ String strVal = ((CONSTANT_Utf8_info) (coffiClass.constant_pool[((CONSTANT_String_info) constVal).string_index])).convert();
+ byte[] utf8Val = CONSTANT_Utf8_info.toUtf8(strVal);
+ constVal = new String(Base64.encode(utf8Val)); // constVal is String
+ }
+
+ bclass.addField(new SootField(fieldName, fieldType,
+ modifiers, constVal) );
+ }
+
sootResolver.assertResolvedClassForType(fieldType);
}