0N/A/*
2362N/A * Copyright (c) 2001, 2002, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
0N/A * published by the Free Software Foundation.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/A
0N/A/**
0N/A * @test
0N/A * @bug 4408582
0N/A * @summary Test fix for: JDWP: WatchpointEvents outside of class filtered out
0N/A *
0N/A * @author Tim Bell
0N/A *
0N/A * @run build TestScaffold VMConnection TargetListener TargetAdapter
0N/A * @run compile -g FieldWatchpoints.java
0N/A * @run main/othervm FieldWatchpoints
0N/A */
0N/Aimport com.sun.jdi.*;
0N/Aimport com.sun.jdi.event.*;
0N/Aimport java.util.*;
0N/A
0N/Aclass A extends Object {
0N/A public static int aField = 0;
0N/A}
0N/A
0N/Aclass B extends A {
0N/A}
0N/A
0N/Aclass FieldWatchpointsDebugee {
0N/A public void update (){
0N/A /* test direct modify access by other class */
0N/A A.aField = 7;
0N/A B.aField = 11;
0N/A }
0N/A public void access (){
0N/A /* test direct read access by other class */
0N/A System.out.print("aField is: ");
0N/A System.out.println(A.aField);
0N/A }
0N/A public static void main(String[] args){
0N/A A testA = new A();
0N/A B testB = new B();
0N/A FieldWatchpointsDebugee my =
0N/A new FieldWatchpointsDebugee();
0N/A my.update();
0N/A my.access();
0N/A }
0N/A}
0N/A
0N/Apublic class FieldWatchpoints extends TestScaffold {
0N/A boolean fieldModifyReported = false;
0N/A boolean fieldAccessReported = false;
0N/A
0N/A FieldWatchpoints (String args[]) {
0N/A super(args);
0N/A }
0N/A
0N/A public static void main(String[] args) throws Exception {
0N/A new FieldWatchpoints (args).startTests();
0N/A }
0N/A
0N/A protected void runTests() throws Exception {
0N/A startTo("FieldWatchpointsDebugee", "update", "()V");
0N/A
0N/A try {
0N/A /*
0N/A * Set a modification watch on aField
0N/A */
0N/A ReferenceType rt = findReferenceType("A");
0N/A String fieldName = "aField";
0N/A Field field = rt.fieldByName(fieldName);
0N/A if (field == null) {
0N/A throw new Exception ("Field name not found: " + fieldName);
0N/A }
0N/A com.sun.jdi.request.EventRequest req =
0N/A eventRequestManager().createModificationWatchpointRequest(field);
0N/A req.setSuspendPolicy(com.sun.jdi.request.EventRequest.SUSPEND_ALL);
0N/A req.enable();
0N/A
0N/A /*
0N/A * Set an access watch on aField
0N/A */
0N/A req =
0N/A eventRequestManager().createAccessWatchpointRequest(field);
0N/A req.setSuspendPolicy(com.sun.jdi.request.EventRequest.SUSPEND_ALL);
0N/A req.enable();
0N/A
0N/A addListener (new TargetAdapter() {
0N/A EventSet lastSet = null;
0N/A
0N/A public void eventSetReceived(EventSet set) {
0N/A lastSet = set;
0N/A }
0N/A public void fieldModified(ModificationWatchpointEvent event) {
0N/A System.out.println("Field modified: " + event);
0N/A fieldModifyReported = true;
0N/A lastSet.resume();
0N/A }
0N/A public void fieldAccessed(AccessWatchpointEvent event) {
0N/A System.out.println("Field accessed: " + event);
0N/A fieldAccessReported = true;
0N/A lastSet.resume();
0N/A }
0N/A });
0N/A
0N/A vm().resume();
0N/A
0N/A } catch (Exception ex){
0N/A ex.printStackTrace();
0N/A testFailed = true;
0N/A } finally {
0N/A // Allow application to complete and shut down
0N/A resumeToVMDisconnect();
0N/A }
0N/A if (!testFailed && fieldModifyReported && fieldAccessReported) {
0N/A System.out.println("FieldWatchpoints: passed");
0N/A } else {
0N/A throw new Exception("FieldWatchpoints: failed");
0N/A }
0N/A }
0N/A}