Skip to content
Closed
Changes from all 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 @@ -262,6 +262,29 @@ public String toString() {


private Hashtable<String,SignatureSet> usedSigs;

private static String[] nativeSourcesCache;
private static Map<String, Boolean> nativeClassUsageCache = new HashMap<String, Boolean>();
private static Map<String, Boolean> nativeMethodUsageCache = new HashMap<String, Boolean>();

private static void resetNativeUsageCaches(String[] nativeSources) {
if (nativeSourcesCache != nativeSources) {
nativeSourcesCache = nativeSources;
nativeClassUsageCache = new HashMap<String, Boolean>();
nativeMethodUsageCache = new HashMap<String, Boolean>();
}
}

private String functionPointer;

private String getFunctionPointer() {
if (functionPointer == null) {
StringBuilder b = new StringBuilder();
this.appendFunctionPointer(b);
functionPointer = b.toString();
}
return functionPointer;
}

// [ddyer 4/2017] avoid creating a lot of temporary objects.
// more than 3x faster than the old way.
Expand Down Expand Up @@ -307,6 +330,7 @@ public boolean isMethodUsed(BytecodeMethod bm0) {
*/
public boolean isMethodUsedByNative(String[] nativeSources, ByteCodeClass cls) {
if (nativeSources == null) return false;
resetNativeUsageCaches(nativeSources);
if (nativeSources == usedByNativeSources) {
return usedByNative;
}
Expand All @@ -318,12 +342,32 @@ public boolean isMethodUsedByNative(String[] nativeSources, ByteCodeClass cls) {
return false;
}

String str = getFunctionPointer();
Boolean cachedMethodUsage = nativeMethodUsageCache.get(str);
if (cachedMethodUsage != null) {
usedByNative = cachedMethodUsage.booleanValue();
if (cls != null) {
if (cachedMethodUsage.booleanValue()) {
cls.setUsedByNative(true);
} else {
Boolean cachedClassUsage = nativeClassUsageCache.get(clsName);
if (cachedClassUsage != null && !cachedClassUsage.booleanValue()) {
cls.setUsedByNative(false);
}
}
}
return cachedMethodUsage.booleanValue();
}

Boolean cachedClassUsage = nativeClassUsageCache.get(clsName);
if (cls != null && cachedClassUsage != null && !cachedClassUsage.booleanValue()) {
usedByNative = false;
cls.setUsedByNative(false);
nativeMethodUsageCache.put(str, Boolean.FALSE);
return false;
}

// check native code
StringBuilder b = new StringBuilder();
this.appendFunctionPointer(b);
String str = b.toString();
boolean foundClassName = false;
for(String s : nativeSources) {
if (cls != null && !foundClassName && s.contains(clsName)) {
Expand All @@ -334,17 +378,23 @@ public boolean isMethodUsedByNative(String[] nativeSources, ByteCodeClass cls) {
usedByNative = true;
if (cls != null) {
cls.setUsedByNative(true);
nativeClassUsageCache.put(clsName, Boolean.TRUE);
}
nativeMethodUsageCache.put(str, Boolean.TRUE);
return true;
}
}
if (cls != null && cachedClassUsage == null) {
nativeClassUsageCache.put(clsName, Boolean.valueOf(foundClassName));
}
if (!foundClassName && cls != null) {
// We didn't find the class at all.
// Let's record that as it will save us time
// when looking up other methods in this class.
cls.setUsedByNative(false);
}
usedByNative = false;
nativeMethodUsageCache.put(str, Boolean.FALSE);
return false;
}

Expand Down
Loading