Commit 157b033b authored by Lukáš Marek's avatar Lukáš Marek

Added more class id work

 - class loaders
 - resolver on server side
parent 3f7804ef
......@@ -60,7 +60,7 @@
</target>
<target name="compile-test" depends="compile-disl,compile-dislre-dispatch">
<javac srcdir="${src.dislre.server}" includes="ch/usi/dag/dislreserver/remoteanalysis/** ch/usi/dag/dislreserver/objectid/**" destdir="bin" debug="true" includeAntRuntime="false">
<javac srcdir="${src.dislre.server}" includes="ch/usi/dag/dislreserver/remoteanalysis/** ch/usi/dag/dislreserver/objectid/** ch/usi/dag/dislreserver/classid/**" destdir="bin" debug="true" includeAntRuntime="false">
<classpath refid="buildpath" />
</javac>
<javac srcdir="${src.test}" destdir="bin" debug="true" includeAntRuntime="false">
......
......@@ -4,6 +4,8 @@
#include <stdlib.h>
#include <string.h>
#include "../src-agent-c/jvmtihelper.h"
// initial buffer size
static const size_t INIT_BUFF_SIZE = 512;
// max limit buffer size
......
......@@ -16,8 +16,8 @@
#include "../src-agent-c/comm.h"
// TODO remove when trunk merged
static const int TRUE = 1;
static const int FALSE = 0;
#define TRUE 1
#define FALSE 0
#include "messagetype.h"
#include "buffer.h"
......@@ -36,6 +36,7 @@ static char host_name[1024];
static char port_number[6]; // including final 0
static jvmtiEnv * jvmti_env;
static int jvm_started = FALSE;
// *** Protected by connection lock ***
......@@ -252,7 +253,7 @@ static void pack_string_java(buffer * buff, jstring to_send, JNIEnv * jni_env) {
(*jni_env)->ReleaseStringUTFChars(jni_env, to_send, str);
}
static jlong get_objectid(jobject obj) {
static jlong get_object_id(jobject obj) {
jlong obj_id;
......@@ -285,7 +286,7 @@ static jlong get_objectid(jobject obj) {
static void pack_object(buffer * buff, jobject to_send) {
pack_long(buff, get_objectid(to_send));
pack_long(buff, get_object_id(to_send));
}
static void pack_class(buffer * buff, jclass to_send) {
......@@ -302,18 +303,47 @@ static void pack_class(buffer * buff, jclass to_send) {
// ******************* analysis helper methods *******************
static void analysis_start(buffer * buff, jint analysis_method_id) {
static jint analysis_start(jint analysis_method_id) {
// send analysis msg
// TODO
/*
static __thread jint thread_id = 0;
static __thread jint preferred_buffer;
if(thread_id == 0) {
thread_id = get_new_thread_id();
acquire_buff()
}
else {
acquire_buff(preferred_buffer)
}
*/
// preferred_buffer = sid;
// get session id - free buffer pos
jint sid = acquire_buff();
buffer * buff = &buffs[sid];
// analysis msg
pack_int(buff, MSG_ANALYZE);
// send method id
// method id
pack_int(buff, analysis_method_id);
// TODO
// thread id
//pack_int(buff, thread_id);
return sid;
}
static void analysis_end(buffer * buff) {
static void analysis_end(jint sid) {
send_buffer_schedule(buff);
send_buffer_schedule(&buffs[sid]);
release_buff(sid);
}
// TODO lock each callback using global lock
......@@ -336,8 +366,17 @@ void JNICALL jvmti_callback_class_file_load_hook( jvmtiEnv *jvmti_env,
buffer * buff = &buffs[buff_id];
// retrieve class loader id
// TODO - we need mechanism to identify loader
jlong loader_id = 0;
if(loader != NULL) { // bootstrap class loader has id 0 - invalid object id
if(jvm_started) {
loader_id = get_object_id(loader);
// TODO test highest bit + update class loader number from reference
}
else {
// TODO generate id
}
}
// msg id
pack_int(buff, MSG_NEW_CLASS);
......@@ -374,6 +413,13 @@ void JNICALL jvmti_callback_class_object_free_hook(jvmtiEnv *jvmti_env, jlong ta
release_buff(buff_id);
}
// ******************* START callback *******************
void JNICALL jvmti_callback_class_vm_start_hook(jvmtiEnv *jvmti_env, JNIEnv* jni_env) {
jvm_started = TRUE;
}
// ******************* SHUTDOWN callback *******************
void JNICALL jvmti_callback_class_vm_death_hook(jvmtiEnv *jvmti_env, JNIEnv* jni_env) {
......@@ -430,6 +476,7 @@ JNIEXPORT jint JNICALL Agent_OnLoad(JavaVM *jvm, char *options, void *reserved)
(void) memset(&callbacks, 0, sizeof(callbacks));
callbacks.ClassFileLoadHook = &jvmti_callback_class_file_load_hook;
callbacks.VMStart = &jvmti_callback_class_vm_start_hook;
callbacks.VMDeath = &jvmti_callback_class_vm_death_hook;
callbacks.ObjectFree = &jvmti_callback_class_object_free_hook;
......@@ -439,6 +486,9 @@ JNIEXPORT jint JNICALL Agent_OnLoad(JavaVM *jvm, char *options, void *reserved)
error = (*jvmti_env)->SetEventNotificationMode(jvmti_env, JVMTI_ENABLE, JVMTI_EVENT_CLASS_FILE_LOAD_HOOK, NULL);
check_jvmti_error(jvmti_env, error, "Cannot set class load hook");
error = (*jvmti_env)->SetEventNotificationMode(jvmti_env, JVMTI_ENABLE, JVMTI_EVENT_VM_START, NULL);
check_jvmti_error(jvmti_env, error, "Cannot set jvm start hook");
error = (*jvmti_env)->SetEventNotificationMode(jvmti_env, JVMTI_ENABLE, JVMTI_EVENT_VM_DEATH, NULL);
check_jvmti_error(jvmti_env, error, "Cannot set jvm death hook");
......@@ -472,21 +522,13 @@ JNIEXPORT jint JNICALL Agent_OnLoad(JavaVM *jvm, char *options, void *reserved)
JNIEXPORT jint JNICALL Java_ch_usi_dag_dislre_REDispatch_analysisStart
(JNIEnv * jni_env, jclass this_class, jint analysis_method_id) {
// get session id - free buffer pos
jint sid = acquire_buff();
analysis_start(&buffs[sid], analysis_method_id);
// find free buffer
return sid;
return analysis_start(analysis_method_id);
}
JNIEXPORT void JNICALL Java_ch_usi_dag_dislre_REDispatch_analysisEnd
(JNIEnv * jni_env, jclass this_class, jint sid) {
analysis_end(&buffs[sid]);
release_buff(sid);
analysis_end(sid);
}
JNIEXPORT void JNICALL Java_ch_usi_dag_dislre_REDispatch_sendBoolean
......
package ch.usi.dag.dislreserver.classid;
import java.util.HashMap;
import java.util.Map;
import ch.usi.dag.dislreserver.exception.DiSLREServerFatalException;
public class ClassIdResolver {
// TODO re ! change object
static Map<Long, Map<String, Object>> classLoaderMap =
new HashMap<Long, Map<String, Object>>();
// TODO re ! change object
static Map<Integer, Object> classIdMap =
new HashMap<Integer, Object>();
// TODO re ! complete holder
public static void addNewClass(String className, long classLoderId, byte[] classCode) {
// TODO re ! change object
Map<String, Object> classNameMap = classLoaderMap.get(classLoderId);
if(classNameMap == null) {
// TODO re ! change object
classNameMap = new HashMap<String, Object>();
}
// TODO re ! change object
classNameMap.put(className, new Object());
}
public static void createHierarchy(String className, long classLoderId, int classId, int superId) {
// TODO re ! change object
Map<String, Object> classNameMap = classLoaderMap.get(classLoderId);
if(classNameMap == null) {
throw new DiSLREServerFatalException("Class loader not known");
}
// TODO re ! change object
Object obj = classNameMap.get(className);
if(obj == null) {
throw new DiSLREServerFatalException("Class not known");
}
// TODO re ! register hierarchy
}
// TODO re ! change object
public static Object getClass(int classId) {
return classIdMap.get(classId);
}
}
package ch.usi.dag.dislreserver.objectid;
package ch.usi.dag.dislreserver.classid;
public abstract class InvalidClass {
......
......@@ -8,9 +8,9 @@ import java.lang.reflect.Method;
import java.util.LinkedList;
import java.util.List;
import ch.usi.dag.dislreserver.classid.InvalidClass;
import ch.usi.dag.dislreserver.exception.DiSLREServerException;
import ch.usi.dag.dislreserver.msg.analyze.AnalysisResolver.AnalysisMethodHolder;
import ch.usi.dag.dislreserver.objectid.InvalidClass;
import ch.usi.dag.dislreserver.objectid.ObjectId;
import ch.usi.dag.dislreserver.reqdispatch.RequestHandler;
......
......@@ -4,6 +4,7 @@ import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import ch.usi.dag.dislreserver.classid.ClassIdResolver;
import ch.usi.dag.dislreserver.exception.DiSLREServerException;
import ch.usi.dag.dislreserver.reqdispatch.RequestHandler;
......@@ -19,8 +20,8 @@ public class NewClassHandler implements RequestHandler {
int classCodeLength = is.readInt();
byte[] classCode = new byte[classCodeLength];
is.readFully(classCode);
// TODO re ! new class
ClassIdResolver.addNewClass(className, classLoderId, classCode);
}
catch (IOException e) {
throw new DiSLREServerException(e);
......
package ch.usi.dag.disl.test.dispatch;
import ch.usi.dag.dislreserver.objectid.InvalidClass;
import ch.usi.dag.dislreserver.classid.InvalidClass;
import ch.usi.dag.dislreserver.objectid.ObjectId;
import ch.usi.dag.dislreserver.remoteanalysis.RemoteAnalysis;
......
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