From 20511649934fed3e8094b69b5375107b965c62a9 Mon Sep 17 00:00:00 2001 From: Shanliang Jiang Date: Fri, 19 Jul 2013 13:35:01 +0200 Subject: [PATCH] 8014534: Better profiling support Validation of parameters Reviewed-by: sspitsyn, skoivu, mchung --- .../com/sun/demo/jvmti/hprof/Tracker.java | 26 ++++++++++++++++-- jdk/src/share/demo/jvmti/hprof/hprof_class.c | 14 ++++++++-- jdk/src/share/demo/jvmti/hprof/hprof_event.c | 27 ++++++++++++++----- 3 files changed, 57 insertions(+), 10 deletions(-) diff --git a/jdk/src/share/classes/com/sun/demo/jvmti/hprof/Tracker.java b/jdk/src/share/classes/com/sun/demo/jvmti/hprof/Tracker.java index f2e33d72454..96950870be2 100644 --- a/jdk/src/share/classes/com/sun/demo/jvmti/hprof/Tracker.java +++ b/jdk/src/share/classes/com/sun/demo/jvmti/hprof/Tracker.java @@ -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); } } diff --git a/jdk/src/share/demo/jvmti/hprof/hprof_class.c b/jdk/src/share/demo/jvmti/hprof/hprof_class.c index f25f53ad934..fb16784476f 100644 --- a/jdk/src/share/demo/jvmti/hprof/hprof_class.c +++ b/jdk/src/share/demo/jvmti/hprof/hprof_class.c @@ -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); diff --git a/jdk/src/share/demo/jvmti/hprof/hprof_event.c b/jdk/src/share/demo/jvmti/hprof/hprof_event.c index 15dd4ddaa76..7892457d3f8 100644 --- a/jdk/src/share/demo/jvmti/hprof/hprof_event.c +++ b/jdk/src/share/demo/jvmti/hprof/hprof_event.c @@ -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); - tls_push_method(tls_index, method); + 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); - tls_pop_method(tls_index, thread, method); + if (method != NULL) { + tls_pop_method(tls_index, thread, method); + } + (*pstatus) = 0; } }