Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/com/sun/jdi/FieldWatchpoints.java
38855 views
/*1* Copyright (c) 2001, 2002, 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*28* @author Tim Bell29*30* @run build TestScaffold VMConnection TargetListener TargetAdapter31* @run compile -g FieldWatchpoints.java32* @run main/othervm FieldWatchpoints33*/34import com.sun.jdi.*;35import com.sun.jdi.event.*;36import java.util.*;3738class A extends Object {39public static int aField = 0;40}4142class B extends A {43}4445class FieldWatchpointsDebugee {46public void update (){47/* test direct modify access by other class */48A.aField = 7;49B.aField = 11;50}51public void access (){52/* test direct read access by other class */53System.out.print("aField is: ");54System.out.println(A.aField);55}56public static void main(String[] args){57A testA = new A();58B testB = new B();59FieldWatchpointsDebugee my =60new FieldWatchpointsDebugee();61my.update();62my.access();63}64}6566public class FieldWatchpoints extends TestScaffold {67boolean fieldModifyReported = false;68boolean fieldAccessReported = false;6970FieldWatchpoints (String args[]) {71super(args);72}7374public static void main(String[] args) throws Exception {75new FieldWatchpoints (args).startTests();76}7778protected void runTests() throws Exception {79startTo("FieldWatchpointsDebugee", "update", "()V");8081try {82/*83* Set a modification watch on aField84*/85ReferenceType rt = findReferenceType("A");86String fieldName = "aField";87Field field = rt.fieldByName(fieldName);88if (field == null) {89throw new Exception ("Field name not found: " + fieldName);90}91com.sun.jdi.request.EventRequest req =92eventRequestManager().createModificationWatchpointRequest(field);93req.setSuspendPolicy(com.sun.jdi.request.EventRequest.SUSPEND_ALL);94req.enable();9596/*97* Set an access watch on aField98*/99req =100eventRequestManager().createAccessWatchpointRequest(field);101req.setSuspendPolicy(com.sun.jdi.request.EventRequest.SUSPEND_ALL);102req.enable();103104addListener (new TargetAdapter() {105EventSet lastSet = null;106107public void eventSetReceived(EventSet set) {108lastSet = set;109}110public void fieldModified(ModificationWatchpointEvent event) {111System.out.println("Field modified: " + event);112fieldModifyReported = true;113lastSet.resume();114}115public void fieldAccessed(AccessWatchpointEvent event) {116System.out.println("Field accessed: " + event);117fieldAccessReported = true;118lastSet.resume();119}120});121122vm().resume();123124} catch (Exception ex){125ex.printStackTrace();126testFailed = true;127} finally {128// Allow application to complete and shut down129resumeToVMDisconnect();130}131if (!testFailed && fieldModifyReported && fieldAccessReported) {132System.out.println("FieldWatchpoints: passed");133} else {134throw new Exception("FieldWatchpoints: failed");135}136}137}138139140