Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix string modeling for springboot #2

Open
wants to merge 8 commits into
base: declarative-config
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1117,6 +1117,8 @@ public static void ensureInitialized() {

public static final Symbol<Signature> String_byte_array_int_int = StaticSymbols.putSignature(Type.java_lang_String, Type._byte_array, Type._int, Type._int);

public static final Symbol<Signature> _boolean_byte_array_byte_array = StaticSymbols.putSignature(Type._boolean, Type._byte_array, Type._byte_array);

public static final Symbol<Signature> _void_int_int_char_array_int = StaticSymbols.putSignature(Type._void, Type._int, Type._int, Type._char_array, Type._int);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -838,6 +838,7 @@ public Meta(EspressoContext context) {

java_lang_StringLatin1 = knownKlass(Type.java_lang_StringLatin1);
java_lang_StringLatin1_newString = java_lang_StringLatin1.lookupMethod(getNames().getOrCreate("newString"), Signature.String_byte_array_int_int);
java_lang_StringLatin1_equals = java_lang_StringLatin1.lookupMethod(getNames().getOrCreate("equals"), Signature._boolean_byte_array_byte_array);

java_lang_StringUTF16 = knownKlass(Type.java_lang_StringUTF16);
java_lang_StringUTF16_newString = java_lang_StringUTF16.lookupMethod(getNames().getOrCreate("newString"), Signature.String_byte_array_int_int);
Expand Down Expand Up @@ -1454,6 +1455,7 @@ private DiffVersionLoadHelper diff() {
public final ObjectKlass java_lang_StringLatin1;

public final Method java_lang_StringLatin1_newString;
public final Method java_lang_StringLatin1_equals;

public final ObjectKlass java_lang_StringUTF16;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2136,11 +2136,16 @@ private void putPoolConstant(VirtualFrame frame, int top, char cpi, int opcode)
} else if (constant instanceof StringConstant) {
assert opcode == LDC || opcode == LDC_W;
StaticObject internedString = pool.resolvedStringAt(cpi);
Meta meta = getMeta();
StaticObject obj = meta.toGuestString(meta.toHostString(internedString));
SPouT.markObjectWithIFTaint(obj);
//TODO: (annotate string and maybe clone?)
putObject(frame, top, obj);
//TODO: (this is definitively not correct! Maybe clone properly and annotate?)
if (SPouT.generateIFTaint()) {
Meta meta = getMeta();
StaticObject obj = meta.toGuestString(meta.toHostString(internedString));
SPouT.markObjectWithIFTaint(obj);
putObject(frame, top, obj);
}
else {
putObject(frame, top, internedString);
}
} else if (constant instanceof ClassConstant) {
assert opcode == LDC || opcode == LDC_W;
Klass klass = pool.resolvedKlassAt(getDeclaringKlass(), cpi);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -529,6 +529,10 @@ public static void markWithIFTaint(VirtualFrame frame, int top){
AnnotatedVM.putAnnotations(frame, top, a);
}

public static boolean generateIFTaint() {
return (analyze && config.analyzeControlFlowTaint());
}

public static void markObjectWithIFTaint(StaticObject obj) {
if(!analyze || !config.analyzeControlFlowTaint()) return;
if (obj == StaticObject.NULL) return;
Expand Down Expand Up @@ -1566,20 +1570,50 @@ public static StaticObject stringConcat(StaticObject self, StaticObject other, M

}

// this is a faithful re-implementation of String.equals()
private static boolean stringEqualsConcrete(StaticObject self, StaticObject other, Meta meta) {
if (self == other) {
return true;
}

if (!other.isString()) {
return false;
}

boolean COMPACT_STRINGS = meta.java_lang_String_COMPACT_STRINGS.getBoolean(meta.java_lang_String.getStatics());
Object this_coder = meta.java_lang_String_coder.getValue(self);
Object other_coder = meta.java_lang_String_coder.getValue(other);

if (COMPACT_STRINGS && this_coder != other_coder) {
return false;
}

Object this_value = meta.java_lang_String_value.getValue(self);
Object other_value = meta.java_lang_String_value.getValue(other);
return (boolean) meta.java_lang_StringLatin1_equals.invokeMethod(null, new Object[] {this_value, other_value});

}

@CompilerDirectives.TruffleBoundary
public static Object stringEquals(StaticObject self, StaticObject other, Meta meta) {
String cSelf = meta.toHostString(self);
String cOther = meta.toHostString(other);
boolean areEqual = cSelf.equals(cOther);
if (!analyze || !self.hasAnnotations() && !other.hasAnnotations()) {
return areEqual;
}
Annotations a = analysis.stringEquals(cSelf,
cOther,
getStringAnnotations(self),
getStringAnnotations(other));
if(a != null) return new AnnotatedValue(areEqual, a);
else return areEqual;
boolean areEqual = stringEqualsConcrete(self, other, meta);
if (!analyze) return areEqual;
if (self.hasAnnotations() || (!StaticObject.isNull(other) && other.hasAnnotations())) {
String cSelf = meta.toHostString(self);
String cOther = meta.toHostString(other);
Annotations a = analysis.stringEquals(cSelf,
cOther,
getStringAnnotations(self),
getStringAnnotations(other));
if(a != null) {
return new AnnotatedValue(areEqual, a);
}
}
// todo: maybe this can be encoded?
if (self.hasAnnotations() && StaticObject.isNull(other)) {
log("not recording string == null");
}
return areEqual;
}

@CompilerDirectives.TruffleBoundary
Expand Down