To protect your data, the CISO officer has suggested users to enable GitLab 2FA as soon as possible.

Commit 0885880d authored by john's avatar john
Browse files

class store now defaults to the agent working directory

parent 6a0dac39
......@@ -45,6 +45,8 @@
#define MINOR_VERSION(v) (int)(((v) & JVMTI_VERSION_MASK_MINOR ) >> JVMTI_VERSION_SHIFT_MINOR)
#define MICRO_VERSION(v) (int)(((v) & JVMTI_VERSION_MASK_MICRO ) >> JVMTI_VERSION_SHIFT_MICRO)
#define FILE_SEPARATOR_CHAR '/'
#define STORE_CLASS_FILE_BASE "DACAPO_STORE"
#define DEFAULT_STORE_CLASS_FILE_BASE "store"
......@@ -83,7 +85,7 @@ jboolean instrumentClasses = FALSE;
jboolean methodCalls = FALSE;
jboolean loadClasses = FALSE;
jboolean storeClassFilesTXed = FALSE;
char storeClassFileBase[8192];
char* storeClassFileBase = NULL; // [8192];
jboolean breakOnLoad = FALSE;
char* breakOnLoadClass = NULL;
......@@ -338,12 +340,6 @@ Agent_OnLoad(JavaVM *vm, char *options, void *reserved)
thread_init();
call_chain_init();
/* */
char* storeClassFile = getenv(STORE_CLASS_FILE_BASE);
if (storeClassFile == NULL)
storeClassFile = DEFAULT_STORE_CLASS_FILE_BASE;
strcpy(storeClassFileBase,storeClassFile);
/* get capabilities */
processCapabilities();
......@@ -434,6 +430,18 @@ static void processOptions() {
isSelected(OPT_METHOD_INSTR,NULL) ||
isSelected(OPT_ALLOCATE,NULL);
char* storeDir = NULL;
if (isSelected(OPT_STORE_DIRECTORY,&storeDir)) {
storeClassFileBase = storeDir;
} else {
int agentOptionsLength = strlen(agentOptions);
int slashLength = (agentOptionsLength<=0 || agentOptions[agentOptionsLength-1]=='/')?0:1;
storeClassFileBase = (char*)malloc(sizeof(char)*(agentOptionsLength+slashLength+strlen(DEFAULT_STORE_CLASS_FILE_BASE)+1));
strcpy(storeClassFileBase,agentOptions);
if (slashLength!=0) storeClassFileBase[agentOptionsLength++] = FILE_SEPARATOR_CHAR;
strcpy(storeClassFileBase+agentOptionsLength,DEFAULT_STORE_CLASS_FILE_BASE);
}
defineCallbacks();
}
......@@ -568,6 +576,22 @@ static void generateFileName(char* file_name, int max_file_name_len) {
file_name[max_file_name_len-1]='\0';
}
static char* generateTmpClassFileName() {
int agentOptionsLength = strlen(agentOptions);
int slashLength = (agentOptions<=0 || agentOptions[agentOptionsLength-1]=='/')?0:1;
char* classFileName = (char*)malloc(sizeof(char)*(agentOptionsLength+slashLength+strlen(TMP_FILE_NAME)+1));
if (0<agentOptionsLength) {
strcpy(classFileName, agentOptions);
if (slashLength!=0)
classFileName[agentOptionsLength++] = '/';
}
strcpy(classFileName+agentOptionsLength,TMP_FILE_NAME);
return classFileName;
}
/* packages to be excluded from transformation */
#define ASM_PACKAGE_NAME "org/objectweb/asm/"
#define DACAPO_PACKAGE_NAME "org/dacapo/instrument/"
......@@ -655,11 +679,15 @@ callbackClassFileLoadHook(jvmtiEnv *jvmti, JNIEnv* env,
if (instrumentClasses && isNotExcluded(name)) {
/* strncmp(DACAPO_PACKAGE_NAME,name,strlen(DACAPO_PACKAGE_NAME))!=0) { */
char command[1024];
/*
char outfile[256];
char infile [256];
generateFileName(outfile, sizeof(outfile));
generateFileName(infile, sizeof(infile));
*/
char* outfile = generateTmpClassFileName();
char* infile = generateTmpClassFileName();
writeClassData(outfile,class_data,class_data_len);
......@@ -677,6 +705,9 @@ callbackClassFileLoadHook(jvmtiEnv *jvmti, JNIEnv* env,
if (invokeProcessClassFile(jarSet, infile, outfile, name, agentOptions) == 0) {
readClassData(infile,new_class_data,new_class_data_len);
}
free(infile);
free(outfile);
}
rawMonitorExit(&lockClass);
......
......@@ -5,6 +5,7 @@
#define OPT_CLINIT "clinit"
#define OPT_STORE_CLASS_FILE "store"
#define OPT_STORE_DIRECTORY "store_dir"
#define OPT_METHOD_EVENTS "method_events"
#define OPT_METHOD_INSTR "method_instr"
#define OPT_LOG_START "log_start"
......
......@@ -4,8 +4,10 @@ import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.PrintStream;
import java.util.LinkedList;
import java.util.Properties;
import java.util.TreeMap;
import java.util.Vector;
import org.dacapo.instrument.instrumenters.Instrumenter;
import org.dacapo.instrument.instrumenters.InstrumenterFactory;
......@@ -48,7 +50,8 @@ public class Instrument extends Instrumenter {
TreeMap<String,Integer> methodToLargestLocal = new TreeMap<String,Integer>();
// read the class to do some pre-processing
ClassReader reader = readClassFromFile(infile);
byte[] classBytes = readClassBytesFromFile(infile);
ClassReader reader = new ClassReader(classBytes);
ClassWriter writer = new ClassWriter(ClassWriter.COMPUTE_MAXS);
ClassVisitor cv = writer;
......@@ -59,7 +62,7 @@ public class Instrument extends Instrumenter {
reader.accept(cv,ClassReader.EXPAND_FRAMES);
reader = readClassFromFile(infile);
reader = new ClassReader(classBytes);
cv = writer = new ClassWriter(ClassWriter.COMPUTE_MAXS);
......@@ -99,15 +102,48 @@ public class Instrument extends Instrumenter {
}
}
private static ClassReader readClassFromFile(String infile) throws Exception {
FileInputStream is = null;
private static final int DEFAULT_CLASS_FILE_SIZE = 1024;
private static final long RIDICULOUS_CLASS_SIZE = 2 * 1024 * 1024;
private static byte[] readClassBytesFromFile(String infile) throws Exception {
byte[] data = null;
byte[] buffer = new byte[DEFAULT_CLASS_FILE_SIZE];
LinkedList<byte[]> segments = new LinkedList<byte[]>();
File file = new File(infile);
if (!file.exists() || file.isDirectory() && !file.canRead() && RIDICULOUS_CLASS_SIZE<file.length())
return null;
FileInputStream is = new FileInputStream(file);
int totalRead = 0;
try {
is = new FileInputStream(infile);
ClassReader reader = new ClassReader(is);
return reader;
int dataRead = 0;
do {
dataRead = is.read(buffer);
if (0<dataRead) {
totalRead += dataRead;
if (dataRead == buffer.length) {
segments.addLast(buffer);
buffer = new byte[DEFAULT_CLASS_FILE_SIZE];
} else {
byte[] segment = new byte[dataRead];
System.arraycopy(buffer, 0, segment, 0, dataRead);
segments.addLast(segment);
}
}
} while (dataRead >= 0);
} finally {
if (is != null) is.close();
is.close();
}
data = new byte[totalRead];
int position = 0;
for(byte[] segment: segments) {
System.arraycopy(segment, 0, data, position, segment.length);
position += segment.length;
}
return data;
}
private static void writeClassToFile(ClassWriter writer, String outfile) throws Exception {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment