< prev index next >

test/com/sun/jdi/InstanceFilter.java

Print this page
rev 11659 : 8076154: com/sun/jdi/InstanceFilter.java failing due to missing MethodEntryRequest calls
Summary: Some jdi tests are failing due to missing MethodEntryRequest events during the test execution.
Reviewed-by: duke
   1 /*
   2  * Copyright (c) 2000, 2002, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */


  87 
  88     /**
  89      * Override TestScaffold.methodEntered.  This should get called
  90      * once for each method named in 'expectedMethods', and for
  91      * the instance that we select to filter on.
  92      */
  93     public void methodEntered(MethodEntryEvent event) {
  94         if (testFailed) {
  95             return;
  96         }
  97         // Find the instance and verify that it is
  98         // the one we want.
  99         ObjectReference theThis;
 100         try {
 101             theThis = event.thread().frame(0).thisObject();
 102         } catch (IncompatibleThreadStateException ee) {
 103             failure("FAILED: Exception occured in methodEntered: " + ee);
 104             return;
 105         }
 106         if (theThis == null) {
 107             // This happens when the thread has exited.



 108             methodEntryRequest.disable();
 109             return;
 110         }
 111 
 112         if (!theThis.equals(theInstance)) {
 113             failure("FAILED: Got a hit on a non-selected instance");
 114         }
 115 
 116         // fail if we don't get called for each of the expected methods
 117         {
 118             String methodStr = event.location().method().name();
 119 
 120             if (methodCount >= expectedMethods.length) {
 121                 failure("FAILED: Got too many methodEntryEvents");
 122             } else if (methodStr.indexOf(expectedMethods[methodCount]) == -1) {
 123                 failure("FAILED: Expected method: " + expectedMethods[methodCount]);
 124             }
 125             methodCount++;
 126             println("Method: " + methodStr);
 127         }
 128     }
 129 
 130     protected void runTests() throws Exception {
 131 
 132         BreakpointEvent bpe = startTo("InstanceFilterTarg", "go", "()V");
 133         targetClass = bpe.location().declaringType();
 134 
 135         Field field = targetClass.fieldByName("second");
 136         theInstance = (ObjectReference)(targetClass.getValue(field));
 137 
 138         EventRequestManager mgr = vm().eventRequestManager();
 139         methodEntryRequest = mgr.createMethodEntryRequest();
 140         methodEntryRequest.addInstanceFilter(theInstance);




 141         methodEntryRequest.enable();
 142 
 143         listenUntilVMDisconnect();
 144 
 145         if (!testFailed && methodCount < expectedMethods.length) {
 146             failure("FAILED: Expected " + expectedMethods.length + " events, only got "
 147                     + methodCount);
 148         }
 149         if (!testFailed) {
 150             println("InstanceFilter: passed");
 151         } else {
 152             throw new Exception("InstanceFilter: failed");
 153         }
 154     }
 155 }
   1 /*
   2  * Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */


  87 
  88     /**
  89      * Override TestScaffold.methodEntered.  This should get called
  90      * once for each method named in 'expectedMethods', and for
  91      * the instance that we select to filter on.
  92      */
  93     public void methodEntered(MethodEntryEvent event) {
  94         if (testFailed) {
  95             return;
  96         }
  97         // Find the instance and verify that it is
  98         // the one we want.
  99         ObjectReference theThis;
 100         try {
 101             theThis = event.thread().frame(0).thisObject();
 102         } catch (IncompatibleThreadStateException ee) {
 103             failure("FAILED: Exception occured in methodEntered: " + ee);
 104             return;
 105         }
 106         if (theThis == null) {
 107             // This happens when the thread has exited or when a
 108             // static method is called. Setting an instance
 109             // filter does not prevent this event from being
 110             // emitted with a this that is null.
 111             methodEntryRequest.disable();
 112             return;
 113         }
 114 
 115         if (!theThis.equals(theInstance)) {
 116             failure("FAILED: Got a hit on a non-selected instance");
 117         }
 118 
 119         // fail if we don't get called for each of the expected methods
 120         {
 121             String methodStr = event.location().method().name();
 122 
 123             if (methodCount >= expectedMethods.length) {
 124                 failure("FAILED: Got too many methodEntryEvents");
 125             } else if (methodStr.indexOf(expectedMethods[methodCount]) == -1) {
 126                 failure("FAILED: Expected method: " + expectedMethods[methodCount]);
 127             }
 128             methodCount++;
 129             println("Method: " + methodStr);
 130         }
 131     }
 132 
 133     protected void runTests() throws Exception {
 134 
 135         BreakpointEvent bpe = startTo("InstanceFilterTarg", "go", "()V");
 136         targetClass = bpe.location().declaringType();
 137 
 138         Field field = targetClass.fieldByName("second");
 139         theInstance = (ObjectReference)(targetClass.getValue(field));
 140 
 141         EventRequestManager mgr = vm().eventRequestManager();
 142         methodEntryRequest = mgr.createMethodEntryRequest();
 143         methodEntryRequest.addInstanceFilter(theInstance);
 144         // Thread filter is needed to prevent MethodEntry events
 145         // to be emitted by the debugee when a static method
 146         // is called on any thread.
 147         methodEntryRequest.addThreadFilter(bpe.thread());
 148         methodEntryRequest.enable();
 149 
 150         listenUntilVMDisconnect();
 151 
 152         if (!testFailed && methodCount < expectedMethods.length) {
 153             failure("FAILED: Expected " + expectedMethods.length + " events, only got "
 154                     + methodCount);
 155         }
 156         if (!testFailed) {
 157             println("InstanceFilter: passed");
 158         } else {
 159             throw new Exception("InstanceFilter: failed");
 160         }
 161     }
 162 }
< prev index next >