8014534: Better profiling support

Validation of parameters

Reviewed-by: sspitsyn, skoivu, mchung
This commit is contained in:
Shanliang Jiang 2013-07-19 13:35:01 +02:00
parent 3d9f33759d
commit 2051164993
3 changed files with 57 additions and 10 deletions

View File

@ -53,7 +53,10 @@ public class Tracker {
public static void ObjectInit(Object obj)
{
if ( engaged != 0 ) {
if ( engaged != 0) {
if (obj == null) {
throw new IllegalArgumentException("Null object.");
}
nativeObjectInit(Thread.currentThread(), obj);
}
}
@ -66,7 +69,10 @@ public class Tracker {
public static void NewArray(Object obj)
{
if ( engaged != 0 ) {
if ( engaged != 0) {
if (obj == null) {
throw new IllegalArgumentException("Null object.");
}
nativeNewArray(Thread.currentThread(), obj);
}
}
@ -82,6 +88,14 @@ public class Tracker {
public static void CallSite(int cnum, int mnum)
{
if ( engaged != 0 ) {
if (cnum < 0) {
throw new IllegalArgumentException("Negative class index");
}
if (mnum < 0) {
throw new IllegalArgumentException("Negative method index");
}
nativeCallSite(Thread.currentThread(), cnum, mnum);
}
}
@ -95,6 +109,14 @@ public class Tracker {
public static void ReturnSite(int cnum, int mnum)
{
if ( engaged != 0 ) {
if (cnum < 0) {
throw new IllegalArgumentException("Negative class index");
}
if (mnum < 0) {
throw new IllegalArgumentException("Negative method index");
}
nativeReturnSite(Thread.currentThread(), cnum, mnum);
}
}

View File

@ -527,7 +527,12 @@ class_get_methodID(JNIEnv *env, ClassIndex index, MethodIndex mnum)
jmethodID method;
info = get_info(index);
HPROF_ASSERT(mnum < info->method_count);
if (mnum >= info->method_count) {
jclass newExcCls = (*env)->FindClass(env, "java/lang/IllegalArgumentException");
(*env)->ThrowNew(env, newExcCls, "Illegal mnum");
return NULL;
}
method = info->method[mnum].method_id;
if ( method == NULL ) {
char * name;
@ -535,7 +540,12 @@ class_get_methodID(JNIEnv *env, ClassIndex index, MethodIndex mnum)
jclass clazz;
name = (char *)string_get(info->method[mnum].name_index);
HPROF_ASSERT(name!=NULL);
if (name==NULL) {
jclass newExcCls = (*env)->FindClass(env, "java/lang/IllegalArgumentException");
(*env)->ThrowNew(env, newExcCls, "Name not found");
return NULL;
}
sig = (char *)string_get(info->method[mnum].sig_index);
HPROF_ASSERT(sig!=NULL);
clazz = class_get_class(env, index);

View File

@ -195,7 +195,12 @@ event_call(JNIEnv *env, jthread thread, ClassIndex cnum, MethodIndex mnum)
HPROF_ASSERT(env!=NULL);
HPROF_ASSERT(thread!=NULL);
HPROF_ASSERT(cnum!=0 && cnum!=gdata->tracker_cnum);
if (cnum == 0 || cnum == gdata->tracker_cnum) {
jclass newExcCls = (*env)->FindClass(env, "java/lang/IllegalArgumentException");
(*env)->ThrowNew(env, newExcCls, "Illegal cnum.");
return;
}
/* Prevent recursion into any BCI function for this thread (pstatus). */
if ( tls_get_tracker_status(env, thread, JNI_FALSE,
@ -204,8 +209,10 @@ event_call(JNIEnv *env, jthread thread, ClassIndex cnum, MethodIndex mnum)
(*pstatus) = 1;
method = class_get_methodID(env, cnum, mnum);
HPROF_ASSERT(method!=NULL);
if (method != NULL) {
tls_push_method(tls_index, method);
}
(*pstatus) = 0;
}
}
@ -248,7 +255,13 @@ event_return(JNIEnv *env, jthread thread, ClassIndex cnum, MethodIndex mnum)
HPROF_ASSERT(env!=NULL);
HPROF_ASSERT(thread!=NULL);
HPROF_ASSERT(cnum!=0 && cnum!=gdata->tracker_cnum);
if (cnum == 0 || cnum == gdata->tracker_cnum) {
jclass newExcCls = (*env)->FindClass(env, "java/lang/IllegalArgumentException");
(*env)->ThrowNew(env, newExcCls, "Illegal cnum.");
return;
}
/* Prevent recursion into any BCI function for this thread (pstatus). */
if ( tls_get_tracker_status(env, thread, JNI_FALSE,
@ -257,8 +270,10 @@ event_return(JNIEnv *env, jthread thread, ClassIndex cnum, MethodIndex mnum)
(*pstatus) = 1;
method = class_get_methodID(env, cnum, mnum);
HPROF_ASSERT(method!=NULL);
if (method != NULL) {
tls_pop_method(tls_index, thread, method);
}
(*pstatus) = 0;
}
}