8014534: Better profiling support
Summary: Validation of parameters
Reviewed-by: sspitsyn, skoivu, mchung
--- a/jdk/src/share/classes/com/sun/demo/jvmti/hprof/Tracker.java Fri Jul 19 12:14:34 2013 +0900
+++ b/jdk/src/share/classes/com/sun/demo/jvmti/hprof/Tracker.java Fri Jul 19 13:35:01 2013 +0200
@@ -53,7 +53,10 @@
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 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 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 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);
}
}
--- a/jdk/src/share/demo/jvmti/hprof/hprof_class.c Fri Jul 19 12:14:34 2013 +0900
+++ b/jdk/src/share/demo/jvmti/hprof/hprof_class.c Fri Jul 19 13:35:01 2013 +0200
@@ -527,7 +527,12 @@
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 @@
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);
--- a/jdk/src/share/demo/jvmti/hprof/hprof_event.c Fri Jul 19 12:14:34 2013 +0900
+++ b/jdk/src/share/demo/jvmti/hprof/hprof_event.c Fri Jul 19 13:35:01 2013 +0200
@@ -195,7 +195,12 @@
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 @@
(*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 @@
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 @@
(*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;
}
}