Skip to content

Commit

Permalink
Merge pull Tencent#790
Browse files Browse the repository at this point in the history
  • Loading branch information
ifshuaishuai committed Sep 28, 2024
1 parent af65077 commit 772d9e3
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.tencent.matrix.trace;

import org.objectweb.asm.MethodVisitor;
import org.objectweb.asm.commons.JSRInlinerAdapter;

public class JSRAdapter extends JSRInlinerAdapter {
JSRAdapter(int api, MethodVisitor mv, int access, String name, String desc, String signature, String[] exceptions) {
super(api, mv, access, name, desc, signature, exceptions);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,7 @@ public int compare(TraceMethod o1, TraceMethod o2) {
}

private class TraceClassAdapter extends ClassVisitor {
private int version;
private String className;
private boolean isABSClass = false;
private boolean hasWindowFocusMethod = false;
Expand All @@ -278,6 +279,7 @@ private class TraceClassAdapter extends ClassVisitor {
@Override
public void visit(int version, int access, String name, String signature, String superName, String[] interfaces) {
super.visit(version, access, name, signature, superName, interfaces);
this.version = version;
this.className = name;
if ((access & Opcodes.ACC_ABSTRACT) > 0 || (access & Opcodes.ACC_INTERFACE) > 0) {
this.isABSClass = true;
Expand All @@ -294,7 +296,12 @@ public MethodVisitor visitMethod(int access, String name, String desc,
if (!hasWindowFocusMethod) {
hasWindowFocusMethod = isWindowFocusChangeMethod(name, desc);
}
return new CollectMethodNode(className, access, name, desc, signature, exceptions);

MethodVisitor collectMethodNode = new CollectMethodNode(className, access, name, desc, signature, exceptions);
if (this.version <= Opcodes.V1_6) {
collectMethodNode = new JSRAdapter(api, collectMethodNode, access, name, desc, signature, exceptions);
}
return collectMethodNode;
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,7 @@ private void listClassFiles(ArrayList<File> classFiles, File folder) {

private class TraceClassAdapter extends ClassVisitor {

private int version;
private String className;
private String superName;
private boolean isABSClass = false;
Expand All @@ -309,6 +310,7 @@ private class TraceClassAdapter extends ClassVisitor {
@Override
public void visit(int version, int access, String name, String signature, String superName, String[] interfaces) {
super.visit(version, access, name, signature, superName, interfaces);
this.version = version;
this.className = name;
this.superName = superName;
this.isActivityOrSubClass = isActivityOrSubClass(className, collectedClassExtendMap);
Expand All @@ -329,8 +331,12 @@ public MethodVisitor visitMethod(int access, String name, String desc,
return super.visitMethod(access, name, desc, signature, exceptions);
} else {
MethodVisitor methodVisitor = cv.visitMethod(access, name, desc, signature, exceptions);
return new TraceMethodAdapter(api, methodVisitor, access, name, desc, this.className,
methodVisitor = new TraceMethodAdapter(api, methodVisitor, access, name, desc, this.className,
hasWindowFocusMethod, isActivityOrSubClass, isNeedTrace);
if (this.version <= Opcodes.V1_6) {
methodVisitor = new JSRAdapter(api, methodVisitor, access, name, desc, signature, exceptions);
}
return methodVisitor;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public class TraceBuildConstants {
public final static String MATRIX_TRACE_APPLICATION_CLASS = "android/app/Application";
public final static String MATRIX_TRACE_METHOD_BEAT_CLASS = "com/tencent/matrix/trace/core/AppMethodBeat";
public final static String MATRIX_TRACE_ON_WINDOW_FOCUS_METHOD_ARGS = "(Z)V";
public static final String[] UN_TRACE_CLASS = {"R.class", "R$", "Manifest", "BuildConfig"};
public static final String[] UN_TRACE_CLASS = {"R.class", "R$", "Manifest", "BuildConfig", "META-INF", "module-info"};
public final static String DEFAULT_BLOCK_TRACE =
"[package]\n"
+ "-keeppackage android/\n"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ class MatrixTrace(
}
val traceClassLoader = TraceClassLoader.getClassLoader(project, allInputs)
methodTracer.trace(dirInputOutMap, jarInputOutMap, traceClassLoader, skipCheckClass)
traceClassLoader.close()

Log.i(TAG, "[doTransform] Step(3)[Trace]... cost:%sms", System.currentTimeMillis() - start)

Expand Down

0 comments on commit 772d9e3

Please sign in to comment.