Path: blob/master/test/jdk/com/sun/jdi/FieldWatchpoints.java
41149 views
/*1* Copyright (c) 2001, 2015, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/**24* @test25* @bug 440858226* @summary Test fix for: JDWP: WatchpointEvents outside of class filtered out27* @author Tim Bell28*29* @run build TestScaffold VMConnection TargetListener TargetAdapter30* @run compile -g FieldWatchpoints.java31* @run driver FieldWatchpoints32*/33import com.sun.jdi.*;34import com.sun.jdi.event.*;35import java.util.*;3637class A extends Object {38public static int aField = 0;39}4041class B extends A {42}4344class FieldWatchpointsDebugee {45public void update (){46/* test direct modify access by other class */47A.aField = 7;48B.aField = 11;49}50public void access (){51/* test direct read access by other class */52System.out.print("aField is: ");53System.out.println(A.aField);54}55public static void main(String[] args){56A testA = new A();57B testB = new B();58FieldWatchpointsDebugee my =59new FieldWatchpointsDebugee();60my.update();61my.access();62}63}6465public class FieldWatchpoints extends TestScaffold {66boolean fieldModifyReported = false;67boolean fieldAccessReported = false;6869FieldWatchpoints (String args[]) {70super(args);71}7273public static void main(String[] args) throws Exception {74new FieldWatchpoints (args).startTests();75}7677protected void runTests() throws Exception {78startTo("FieldWatchpointsDebugee", "update", "()V");7980try {81/*82* Set a modification watch on aField83*/84ReferenceType rt = findReferenceType("A");85String fieldName = "aField";86Field field = rt.fieldByName(fieldName);87if (field == null) {88throw new Exception ("Field name not found: " + fieldName);89}90com.sun.jdi.request.EventRequest req =91eventRequestManager().createModificationWatchpointRequest(field);92req.setSuspendPolicy(com.sun.jdi.request.EventRequest.SUSPEND_ALL);93req.enable();9495/*96* Set an access watch on aField97*/98req =99eventRequestManager().createAccessWatchpointRequest(field);100req.setSuspendPolicy(com.sun.jdi.request.EventRequest.SUSPEND_ALL);101req.enable();102103addListener (new TargetAdapter() {104EventSet lastSet = null;105106public void eventSetReceived(EventSet set) {107lastSet = set;108}109public void fieldModified(ModificationWatchpointEvent event) {110System.out.println("Field modified: " + event);111fieldModifyReported = true;112lastSet.resume();113}114public void fieldAccessed(AccessWatchpointEvent event) {115System.out.println("Field accessed: " + event);116fieldAccessReported = true;117lastSet.resume();118}119});120121vm().resume();122123} catch (Exception ex){124ex.printStackTrace();125testFailed = true;126} finally {127// Allow application to complete and shut down128resumeToVMDisconnect();129}130if (!testFailed && fieldModifyReported && fieldAccessReported) {131System.out.println("FieldWatchpoints: passed");132} else {133throw new Exception("FieldWatchpoints: failed");134}135}136}137138139