From 1a0c261469247afef0bcf8b05109bbdef317412f Mon Sep 17 00:00:00 2001 From: Jim Holmlund Date: Tue, 1 Jul 2008 09:23:00 -0700 Subject: [PATCH] 2157677: ClassPrepareRequest.addSourceNameFilter() does not behave as documented Add proper handling of JVMTI errors. Reviewed-by: tbell --- jdk/src/share/back/eventFilter.c | 15 ++++---- .../com/sun/jdi/SourceNameFilterTest.java | 35 +++++++++++++++---- 2 files changed, 37 insertions(+), 13 deletions(-) diff --git a/jdk/src/share/back/eventFilter.c b/jdk/src/share/back/eventFilter.c index edddeba808c..955cf8813b4 100644 --- a/jdk/src/share/back/eventFilter.c +++ b/jdk/src/share/back/eventFilter.c @@ -492,14 +492,17 @@ eventFilterRestricted_passesFilter(JNIEnv *env, char *sourceName = 0; jvmtiError error = JVMTI_FUNC_PTR(gdata->jvmti,GetSourceFileName) (gdata->jvmti, clazz, &sourceName); - if (error == JVMTI_ERROR_NONE) { - if (sourceName == 0 || !patternStringMatch(sourceName, desiredNamePattern)) { - /* We have no match */ - jvmtiDeallocate(sourceName); - return JNI_FALSE; - } + if (error == JVMTI_ERROR_NONE && + sourceName != 0 && + patternStringMatch(sourceName, desiredNamePattern)) { + // got a hit - report the event + jvmtiDeallocate(sourceName); + break; } + // We have no match, we have no source file name, + // or we got a JVM TI error. Don't report the event. jvmtiDeallocate(sourceName); + return JNI_FALSE; } break; } diff --git a/jdk/test/com/sun/jdi/SourceNameFilterTest.java b/jdk/test/com/sun/jdi/SourceNameFilterTest.java index 1565a8886a8..cb8260646f0 100644 --- a/jdk/test/com/sun/jdi/SourceNameFilterTest.java +++ b/jdk/test/com/sun/jdi/SourceNameFilterTest.java @@ -23,7 +23,7 @@ /** * @test - * @bug 4836939 + * @bug 4836939 6646613 * @summary JDI add addSourceNameFilter to ClassPrepareRequest * * @author jjh @@ -31,7 +31,11 @@ * @run build TestScaffold VMConnection TargetListener TargetAdapter * @run compile -g SourceNameFilterTest.java * @run main SourceNameFilterTest + * @run compile -g:none SourceNameFilterTest.java + * @run main SourceNameFilterTest */ +// The compile -g:none suppresses the lineNumber table to trigger bug 6646613. + import com.sun.jdi.*; import com.sun.jdi.event.*; import com.sun.jdi.request.*; @@ -84,7 +88,6 @@ public class SourceNameFilterTest extends TestScaffold { boolean gotEvent1 = false; boolean gotEvent2 = false; boolean gotEvent3 = false; - ClassPrepareRequest cpReq; boolean shouldResume = false; SourceNameFilterTest (String args[]) { @@ -151,6 +154,18 @@ public class SourceNameFilterTest extends TestScaffold { */ BreakpointEvent bpe = startToMain("SourceNameFilterTarg"); targetClass = bpe.location().declaringType(); + boolean noSourceName = false; + try { + targetClass.sourceName(); + } catch (AbsentInformationException ee) { + noSourceName = true; + } + if (noSourceName) { + println("-- Running with no source names"); + } else { + println("-- Running with source names"); + } + mainThread = bpe.thread(); EventRequestManager erm = vm().eventRequestManager(); addListener(this); @@ -175,7 +190,9 @@ public class SourceNameFilterTest extends TestScaffold { /* * This should cause us to get a class prepare event for - * LoadedLater3 + * LoadedLater3 except in the case where -g:none + * was used to compile so that there is no LineNumberTable + * and therefore, no source name for the class. */ cpReq = erm.createClassPrepareRequest(); cpReq.addSourceNameFilter("SourceNameFilterTest.java"); @@ -186,17 +203,21 @@ public class SourceNameFilterTest extends TestScaffold { if (!gotEvent1) { failure("failure: Did not get a class prepare request " + - "for Loadedlater1"); + "for LoadedLater1"); } if (gotEvent2) { failure("failure: Did get a class prepare request " + - "for Loadedlater2"); + "for LoadedLater2"); } - if (!gotEvent3) { + if (gotEvent3 && noSourceName) { + failure("failure: Did get a class prepare request " + + "for LoadedLater3"); + } + else if (!gotEvent3 && !noSourceName) { failure("failure: Did not get a class prepare request " + - "for Loadedlater3"); + "for LoadedLater3"); } /*