Skip to content

Commit

Permalink
[experimental] suppress some logs
Browse files Browse the repository at this point in the history
  • Loading branch information
kartikeytewari-ul committed Jul 8, 2024
1 parent a61e1d8 commit 70bb37e
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 54 deletions.
2 changes: 2 additions & 0 deletions src/main/java/io/unlogged/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ public class Constants {
// frequency logging
public static final String mapStoreCompileValue = "unlogged$$mapStore";
public static final String probedValue = "Unlogged$Probed$$";

public static final int callParentIdPlaceholder = -1;

private Constants() {
}
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/io/unlogged/Runtime.java
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@ public static Runtime getInstance(String args) {
public static void registerClass(String classInfoBytes, String probesToRecordBase64) {
// System.out.println(
// "New class registration [" + classInfoBytes.getBytes().length + "][" + probesToRecordBase64.getBytes().length + "]");
System.out.println("enter registerClass");
StackTraceElement callerClassAndMethodStack = new Exception().getStackTrace()[1];
try {
Class<?> callerClass = Class.forName(callerClassAndMethodStack.getClassName());
Expand Down Expand Up @@ -289,6 +290,10 @@ public static void registerClass(String classInfoBytes, String probesToRecordBas
}
// System.out.println("Register class ["+ classInfo.getClassId() +"][" + classInfo.getClassName() + "] => " + probesToRecord.size() +
// " probes to record");

System.out.println("decodedClassWeaveInfo = " + decodedClassWeaveInfo);
System.out.println("classInfo = " + classInfo);
System.out.println("probesToRecord = " + probesToRecord);
instance.logger.recordWeaveInfo(decodedClassWeaveInfo, classInfo, probesToRecord);
} else {
// System.out.println("Adding class to pending registrations");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ public void visitInnerClass(String name, String outerName,
@Override
public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) {

// calcuclate probe flag at method level
// calculate probe flag at method level
Boolean alwaysProbeMethodFlag = this.alwaysProbeClassFlag || ProbeFlagUtil.getalwaysProbeMethodFlag(name, access, desc);
Boolean neverProbeMethodFlag = ProbeFlagUtil.getNeverProbeMethodFlag(name);

Expand Down
103 changes: 51 additions & 52 deletions src/main/java/io/unlogged/core/bytecode/method/MethodTransformer.java
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ public void visitLineNumber(int line, Label start) {
// Generate a line number event
// if (config.recordLineNumber()) {
// System.err.println("generateLogging(EventType.LINE_NUMBER, Descriptor.Void, \"\")");
generateLogging(EventType.LINE_NUMBER, Descriptor.Void, "");
// generateLogging(EventType.LINE_NUMBER, Descriptor.Void, "");
// }
instructionIndex++;
}
Expand Down Expand Up @@ -469,19 +469,19 @@ public void visitTypeInsn(int opcode, String type) {
}
} else if (opcode == Opcodes.ANEWARRAY) {
if (config.recordArrayInstructions()) {
int dataId = generateLoggingPreservingStackTop(EventType.NEW_ARRAY, Descriptor.Integer, "");
// int dataId = generateLoggingPreservingStackTop(EventType.NEW_ARRAY, Descriptor.Integer, "");
super.visitTypeInsn(opcode, type); // -> stack: [ARRAYREF]
generateLoggingPreservingStackTop(EventType.NEW_ARRAY_RESULT, Descriptor.Object, "");
// generateLoggingPreservingStackTop(EventType.NEW_ARRAY_RESULT, Descriptor.Object, "");
} else {
super.visitTypeInsn(opcode, type);
}
afterNewArray = true;
} else if (opcode == Opcodes.INSTANCEOF) {
if (config.recordObject()) {
int dataId = generateLoggingPreservingStackTop(EventType.OBJECT_INSTANCEOF, Descriptor.Object,
"Type=" + type);
// int dataId = generateLoggingPreservingStackTop(EventType.OBJECT_INSTANCEOF, Descriptor.Object,
// "Type=" + type);
super.visitTypeInsn(opcode, type); // -> [ result ]
generateLoggingPreservingStackTop(EventType.OBJECT_INSTANCEOF_RESULT, Descriptor.Boolean, "");
// generateLoggingPreservingStackTop(EventType.OBJECT_INSTANCEOF_RESULT, Descriptor.Boolean, "");
} else {
super.visitTypeInsn(opcode, type); // -> [ result ]
}
Expand All @@ -501,9 +501,9 @@ public void visitIntInsn(int opcode, int operand) {
if (config.recordArrayInstructions()) {
// A static operand indicates an element type.
// stack: [SIZE]
int dataId = generateLoggingPreservingStackTop(EventType.NEW_ARRAY, Descriptor.Integer, "");
// int dataId = generateLoggingPreservingStackTop(EventType.NEW_ARRAY, Descriptor.Integer, "");
super.visitIntInsn(opcode, operand); // -> stack: [ARRAYREF]
generateLoggingPreservingStackTop(EventType.NEW_ARRAY_RESULT, Descriptor.Object, "");
// generateLoggingPreservingStackTop(EventType.NEW_ARRAY_RESULT, Descriptor.Object, "");
} else {
super.visitIntInsn(opcode, operand);
}
Expand Down Expand Up @@ -629,7 +629,7 @@ public void visitMethodInsn(int opcode, String owner, String name, String desc,
if (isConstructorChain) {
if (config.recordExecution()) {
// Record an object initialized by this() or super()
generateLogging(EventType.METHOD_OBJECT_INITIALIZED, Descriptor.Object, "");
// generateLogging(EventType.METHOD_OBJECT_INITIALIZED, Descriptor.Object, "");
}
afterInitialization = true;
} else if (newInstruction != null) {
Expand Down Expand Up @@ -658,8 +658,8 @@ public void visitMethodInsn(int opcode, String owner, String name, String desc,
// Constructor call
if (isConstructorChain) {
if (config.recordExecution()) {
super.visitVarInsn(Opcodes.ALOAD, 0);
generateLogging(EventType.METHOD_OBJECT_INITIALIZED, Descriptor.Object, "");
// super.visitVarInsn(Opcodes.ALOAD, 0);
// generateLogging(EventType.METHOD_OBJECT_INITIALIZED, Descriptor.Object, "");
}
afterInitialization = true;
}
Expand All @@ -674,8 +674,8 @@ public void visitMethodInsn(int opcode, String owner, String name, String desc,
// Constructor call
if (isConstructorChain) {
if (config.recordExecution()) {
super.visitVarInsn(Opcodes.ALOAD, 0);
generateLogging(EventType.METHOD_OBJECT_INITIALIZED, Descriptor.Object, "");
// super.visitVarInsn(Opcodes.ALOAD, 0);
// generateLogging(EventType.METHOD_OBJECT_INITIALIZED, Descriptor.Object, "");
}
afterInitialization = true;
}
Expand Down Expand Up @@ -712,14 +712,14 @@ private void generateLocationUpdate(int dataId) {
@Override
public void visitMultiANewArrayInsn(String desc, int dims) {
if (config.recordArrayInstructions()) {
int dataId = nextDataId(EventType.MULTI_NEW_ARRAY, Descriptor.Object, "Type=" + desc);
nextDataId(EventType.MULTI_NEW_ARRAY_OWNER, Descriptor.Object, "");
nextDataId(EventType.MULTI_NEW_ARRAY_ELEMENT, Descriptor.Object, "");
// int dataId = nextDataId(EventType.MULTI_NEW_ARRAY, Descriptor.Object, "Type=" + desc);
// nextDataId(EventType.MULTI_NEW_ARRAY_OWNER, Descriptor.Object, "");
// nextDataId(EventType.MULTI_NEW_ARRAY_ELEMENT, Descriptor.Object, "");
super.visitMultiANewArrayInsn(desc, dims);
super.visitInsn(Opcodes.DUP);
super.visitLdcInsn(dataId);
super.visitMethodInsn(Opcodes.INVOKESTATIC, LOGGER_CLASS, "recordMultiNewArray", "(Ljava/lang/Object;I)V",
false);
// super.visitInsn(Opcodes.DUP);
// super.visitLdcInsn(dataId);
// super.visitMethodInsn(Opcodes.INVOKESTATIC, LOGGER_CLASS, "recordMultiNewArray", "(Ljava/lang/Object;I)V",
// false);
} else {
super.visitMultiANewArrayInsn(desc, dims);
}
Expand Down Expand Up @@ -815,9 +815,9 @@ public void visitInsn(int opcode) {
}
} else if (opcode == Opcodes.ARRAYLENGTH) {
if (config.recordArrayInstructions()) {
int arrayLengthId = generateLoggingPreservingStackTop(EventType.ARRAY_LENGTH, Descriptor.Object, "");
// int arrayLengthId = generateLoggingPreservingStackTop(EventType.ARRAY_LENGTH, Descriptor.Object, "");
super.visitInsn(opcode); // -> [ arraylength ]
generateLoggingPreservingStackTop(EventType.ARRAY_LENGTH_RESULT, Descriptor.Integer, "");
// generateLoggingPreservingStackTop(EventType.ARRAY_LENGTH_RESULT, Descriptor.Integer, "");
} else {
super.visitInsn(opcode);
}
Expand Down Expand Up @@ -877,7 +877,7 @@ public void visitInvokeDynamicInsn(String name, String desc, Handle bsm, Object.
}
String label = sig.toString();

int dataId = generateLogging(EventType.INVOKE_DYNAMIC, Descriptor.Void, label);
// int dataId = generateLogging(EventType.INVOKE_DYNAMIC, Descriptor.Void, label);

if (config.recordParameters()) {
// Generate code to record parameters
Expand All @@ -892,12 +892,12 @@ public void visitInvokeDynamicInsn(String name, String desc, Handle bsm, Object.

// Record remaining parameters
int paramIndex = 0;
while (paramIndex < params.size()) {
generateNewVarInsn(params.getLoadInstruction(paramIndex), params.getLocalVar(paramIndex));
generateLogging(EventType.INVOKE_DYNAMIC_PARAM, params.getRecordDesc(paramIndex),
"Type=" + params.getType(paramIndex).getDescriptor());
paramIndex++;
}
// while (paramIndex < params.size()) {
// generateNewVarInsn(params.getLoadInstruction(paramIndex), params.getLocalVar(paramIndex));
// generateLogging(EventType.INVOKE_DYNAMIC_PARAM, params.getRecordDesc(paramIndex),
// "Type=" + params.getType(paramIndex).getDescriptor());
// paramIndex++;
// }

// Restore parameters from local variables
for (int i = 0; i < params.size(); i++) {
Expand Down Expand Up @@ -960,8 +960,8 @@ public void visitLdcInsn(Object cst) {
if (config.recordObject() &&
!(cst instanceof Integer) && !(cst instanceof Long) &&
!(cst instanceof Double) && !(cst instanceof Float)) {
generateLoggingPreservingStackTop(EventType.OBJECT_CONSTANT_LOAD, Descriptor.Object,
"Type=" + cst.getClass().getName());
// generateLoggingPreservingStackTop(EventType.OBJECT_CONSTANT_LOAD, Descriptor.Object,
// "Type=" + cst.getClass().getName());
}
instructionIndex++;
}
Expand Down Expand Up @@ -1044,25 +1044,24 @@ public void visitFieldInsn(int opcode, String owner, String name, String desc) {
if (opcode == Opcodes.GETSTATIC) {
// Record a resultant value
super.visitFieldInsn(opcode, owner, name, desc); // [] -> [ value ]
generateLoggingPreservingStackTop(EventType.GET_STATIC_FIELD, Descriptor.get(desc), label);
// generateLoggingPreservingStackTop(EventType.GET_STATIC_FIELD, Descriptor.get(desc), label);

} else if (opcode == Opcodes.PUTSTATIC) {
// Record a new value
generateLoggingPreservingStackTop(EventType.PUT_STATIC_FIELD, Descriptor.get(desc), label);
// generateLoggingPreservingStackTop(EventType.PUT_STATIC_FIELD, Descriptor.get(desc), label);
super.visitFieldInsn(opcode, owner, name, desc);

} else if (opcode == Opcodes.GETFIELD) {
int fieldDataId = generateLoggingPreservingStackTop(EventType.GET_INSTANCE_FIELD, Descriptor.Object, label);

generateLocationUpdate(fieldDataId);
// int fieldDataId = generateLoggingPreservingStackTop(EventType.GET_INSTANCE_FIELD, Descriptor.Object, label);
// generateLocationUpdate(fieldDataId);

// Execute GETFIELD
super.visitFieldInsn(opcode, owner, name, desc); // -> [value]

generateLocationUpdate(0);

// Record the result
generateLoggingPreservingStackTop(EventType.GET_INSTANCE_FIELD_RESULT, Descriptor.get(desc), label);
// generateLoggingPreservingStackTop(EventType.GET_INSTANCE_FIELD_RESULT, Descriptor.get(desc), label);

} else {
assert opcode == Opcodes.PUTFIELD;
Expand All @@ -1071,28 +1070,28 @@ public void visitFieldInsn(int opcode, String owner, String name, String desc) {
if (desc.equals("D") || desc.equals("J")) {
int local = newLocal(OpcodesUtil.getAsmType(desc));
// Store a value to a local variable, record an object, and then load the value.
generateNewVarInsn(OpcodesUtil.getStoreInstruction(desc), local);
int fieldDataId = generateLoggingPreservingStackTop(EventType.PUT_INSTANCE_FIELD, Descriptor.Object,
label);
generateNewVarInsn(OpcodesUtil.getLoadInstruction(desc), local);
// generateNewVarInsn(OpcodesUtil.getStoreInstruction(desc), local);
// int fieldDataId = generateLoggingPreservingStackTop(EventType.PUT_INSTANCE_FIELD, Descriptor.Object,
// label);
// generateNewVarInsn(OpcodesUtil.getLoadInstruction(desc), local);

// Record a value.
generateLoggingPreservingStackTop(EventType.PUT_INSTANCE_FIELD_VALUE, Descriptor.get(desc), label);
// generateLoggingPreservingStackTop(EventType.PUT_INSTANCE_FIELD_VALUE, Descriptor.get(desc), label);

generateLocationUpdate(fieldDataId);
// generateLocationUpdate(fieldDataId);

// Original Instruction
super.visitFieldInsn(opcode, owner, name, desc);

generateLocationUpdate(0);

} else {
super.visitInsn(Opcodes.DUP2);
super.visitInsn(Opcodes.SWAP); // -> [object, value, value, object]
int fieldDataId = generateLogging(EventType.PUT_INSTANCE_FIELD, Descriptor.Object, label);
generateLogging(EventType.PUT_INSTANCE_FIELD_VALUE, Descriptor.get(desc), label);
// super.visitInsn(Opcodes.DUP2);
// super.visitInsn(Opcodes.SWAP); // -> [object, value, value, object]
// int fieldDataId = generateLogging(EventType.PUT_INSTANCE_FIELD, Descriptor.Object, label);
// generateLogging(EventType.PUT_INSTANCE_FIELD_VALUE, Descriptor.get(desc), label);

generateLocationUpdate(fieldDataId);
// generateLocationUpdate(fieldDataId);
super.visitFieldInsn(opcode, owner, name, desc);
generateLocationUpdate(0);
}
Expand Down Expand Up @@ -1127,9 +1126,9 @@ public void visitVarInsn(int opcode, int var) {
if (d != null) { // isStore
LocalVariableNode local = variables.getStoreVar(instructionIndex, var);
if (local != null) {
generateLoggingPreservingStackTop(EventType.LOCAL_STORE, d, "Type=" + local.desc);
// generateLoggingPreservingStackTop(EventType.LOCAL_STORE, d, "Type=" + local.desc);
} else {
generateLoggingPreservingStackTop(EventType.LOCAL_STORE, d, "Type=" + d.getString());
// generateLoggingPreservingStackTop(EventType.LOCAL_STORE, d, "Type=" + d.getString());
}
} else if (opcode == Opcodes.RET) {
d = Descriptor.Integer;
Expand All @@ -1148,10 +1147,10 @@ public void visitVarInsn(int opcode, int var) {
if (local != null) {
// System.out.println("Adding local_load for " + local.name + " - " + local.desc + " - " + local.signature);
Descriptor localDesc = Descriptor.get(local.desc);
generateLoggingPreservingStackTop(EventType.LOCAL_LOAD, localDesc, "Type=" + local.desc);
// generateLoggingPreservingStackTop(EventType.LOCAL_LOAD, localDesc, "Type=" + local.desc);
} else {
// System.out.println("Local variable not found");
generateLoggingPreservingStackTop(EventType.LOCAL_LOAD, d, "Type=" + d.getString());
// generateLoggingPreservingStackTop(EventType.LOCAL_LOAD, d, "Type=" + d.getString());
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/io/unlogged/logging/DiscardEventLogger.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public void recordEvent(int dataId, float value) {

@Override
public void recordWeaveInfo(byte[] byteArray, ClassInfo classIdEntry, List<Integer> probeIdsToRecord) {

System.out.println("recordWeaveInfo type-2 called");
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -548,6 +548,7 @@ public void recordEvent(int dataId, float value) {

@Override
public void recordWeaveInfo(byte[] byteArray, ClassInfo classIdEntry, List<Integer> probeIdsToRecord) {
System.out.println("recordWeaveInfo type-1 called");
if (probeIdsToRecord.size() > 0) {
Integer firstProbeIdThisBatch = probeIdsToRecord.get(0);
for (Integer i : probeIdsToRecord) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,7 @@ public void recordEvent(int dataId, float value) {

@Override
public void recordWeaveInfo(byte[] byteArray, ClassInfo classIdEntry, List<Integer> probeIdsToRecord) {
System.out.println("recordWeaveInfo type-3 called");
aggregatedLogger.writeWeaveInfo(byteArray);
}

Expand Down

0 comments on commit 70bb37e

Please sign in to comment.