Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClearFieldAccessWatch/clrfldw001.java
40948 views
/*1* Copyright (c) 2003, 2018, 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*/2223package nsk.jvmti.ClearFieldAccessWatch;2425import java.io.PrintStream;2627public class clrfldw001 {2829native static void setWatch(int fld_ind);30native static void clearWatch(int fld_ind);31native void touchfld0();32native static void check(int fld_ind, boolean flag);33native static int getRes();3435static {36try {37System.loadLibrary("clrfldw001");38} catch (UnsatisfiedLinkError ule) {39System.err.println("Could not load clrfldw001 library");40System.err.println("java.library.path:"41+ System.getProperty("java.library.path"));42throw ule;43}44}4546int fld0 = -1;47static int fld1 = 1;48private clrfldw001a fld2 = new clrfldw001a();49static int fld;5051public static void main(String[] args) {52args = nsk.share.jvmti.JVMTITest.commonInit(args);5354System.exit(run(args, System.out) + 95/*STATUS_TEMP*/);55}5657public static int run(String argv[], PrintStream ref) {58clrfldw001 t = new clrfldw001();59clrfldw001a t_a = new clrfldw001a();60clrfldw001b t_b = new clrfldw001b();61for (int i = 0; i < 5; i++) {62setWatch(i);63}64t_b.start();65clearWatch(1);66fld = fld1 + fld;67check(1, false);68clearWatch(3);69fld -= t_a.fld3[2];70check(3, false);71t.meth01();72try {73t_b.join();74} catch (InterruptedException e) {}75return getRes();76}7778private void meth01() {79clearWatch(0);80touchfld0();81check(0, false);82clearWatch(2);83fld += fld2.fld;84check(2, false);85}86}8788class clrfldw001a {89int[] fld3 = {10, 9, 8, 7, 6};90int fld = 2;91}9293class clrfldw001b extends Thread {94float fld4 = 6.0f;95public void run() {96clrfldw001.clearWatch(4);97clrfldw001.fld += fld4;98clrfldw001.check(4, false);99}100}101102103