Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/demo/jvmti/hprof/UseAllBytecodes.java
38840 views
/*1* Copyright (c) 1996, 2005, 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*/22/*23A simple Java class definition that helps self-test the runtime24interpreter. Used for getfield/putfield, invoke* opcodes and25their _quick variants.2627See src/share/java/runtime/selftest.c for details of the test28environment.29*/3031/* Used to be sun/misc/SelfTest.java */3233interface UseAllBytecodesInterface34{35public void test_an_interface(int p1);36}3738public class UseAllBytecodes implements UseAllBytecodesInterface39{40public int i1, i2;41public float f1, f2;42public double d1, d2;43public long l1, l2;4445public static int si1, si2;46public static float sf1, sf2;47public static double sd1, sd2;48public static long sl1, sl2;4950public UseAllBytecodesInterface interfaceObject;5152public int multi[][][];5354public UseAllBytecodes()55{56/* This constructor is not intended to ever be run. It is here57to force CONSTANT_Methodref constants into the CP */58set_i1(11);59set_i2(22);60set_f1(1.1f);61set_f2(2.2f);62set_d1(1.0);63set_d2(2.0);64set_l1(3);65set_l2(4);6667set_si1(33);68set_si2(44);69set_sf1(3.3f);70set_sf2(4.4f);71set_sd1(3.0);72set_sd2(4.0);73set_sl1(5);74set_sl2(6);7576test_areturn();77test_athrow1();78test_athrow2();79test_athrow3();80test_athrow4();8182/* This puts a CONSTANT_InterfaceMethodref into the CP */83interfaceObject.test_an_interface(1234);8485/* This creates an array and puts it into the CP */86multi = new int[2][3][4];87}8889public UseAllBytecodes(int p1)90{91i1 = p1;92i2 = 12345678; /* This puts a CONSTANT_Integer into the CP */93d1 = (double) p1;94d2 = 1.2e234; /* This puts a CONSTANT_Double into the CP */95}9697public UseAllBytecodes(int p1, int p2)98{99i1 = p1;100i2 = p2;101}102103/* These methods should return something other than their104arguments, so the self test can easily determine that105the correct value was returned. */106public int set_i1(int p1)107{108i1 = p1;109return i1 + 1;110}111112public int set_i2(int p2)113{114i2 = p2;115return i2 + 1;116}117118public float set_f1(float p1)119{120f1 = p1;121return f1 + 1.0e34f;122}123124public float set_f2(float p2)125{126f2 = p2;127return f2 + 1.0e34f;128}129130public double set_d1(double p1)131{132d1 = p1;133return d1 + 1.0e234;134}135136public double set_d2(double p2)137{138d2 = p2;139return d2 + 1.0e234;140}141142public long set_l1(long p1)143{144l1 = p1;145return l1 + 1;146}147148public long set_l2(long p2)149{150l2 = p2;151return l2 + 1;152}153154public static void set_si1(int p1)155{156si1 = p1;157}158159public static void set_si2(int p2)160{161si2 = p2;162}163164public static void set_sf1(float p1)165{166sf1 = p1;167}168169public static void set_sf2(float p2)170{171sf2 = p2;172}173174public static void set_sd1(double p1)175{176sd1 = p1;177}178179public static void set_sd2(double p2)180{181sd2 = p2;182}183184public static void set_sl1(long p1)185{186sl1 = p1;187}188189public static void set_sl2(long p2)190{191sl2 = p2;192}193194public UseAllBytecodes test_areturn()195{196return this;197}198199/* This method does the same thing as set_i1.200It is here to test the invokeinterface opcode. */201public void test_an_interface(int p1)202{203i1 = p1;204}205206/* The following 10 methods test various permutations of207try-and-catch. */208public static void test_athrow1() throws NullPointerException209{210try211{212si1 = -1;213throw new NullPointerException();214}215catch (Exception e)216{217si1 = 1;218}219}220221public static void test_athrow2()222{223int i = 1;224try225{226si1 = -1;227test_athrow1();228}229catch (Exception e)230{231// This should *not* catch the exception;232// should be caught in test_athrow1.233si1 = i + 1;234}235}236237public static void test_athrow3()238{239int i = 1;240try241{242// Ultimately throws NullPointerException243si1 = -1;244si2 = -1;245test_athrow5();246}247catch (NullPointerException np)248{249si1 = i + 1;250}251catch (NoSuchMethodException e)252{253si2 = i + 1;254}255si1++; // total is 3256}257258public static void test_athrow4()259{260int i = 2;261try262{263// Ultimately throws NoSuchMethodException264si1 = -1;265si2 = -1;266test_athrow7();267}268catch (NullPointerException e)269{270si1 = i + 1;271}272catch (NoSuchMethodException nsm)273{274si2 = i + 1;275}276si2++; // total is 4277}278279public static void test_throw_nosuchmethod() throws NoSuchMethodException280{281throw new NoSuchMethodException();282}283284public static void test_throw_nullpointer() throws NullPointerException285{286throw new NullPointerException();287}288289public static void test_athrow5() throws NullPointerException, NoSuchMethodException290{291test_athrow6();292}293294public static void test_athrow6() throws NullPointerException, NoSuchMethodException295{296test_throw_nullpointer();297}298299public static void test_athrow7() throws NullPointerException, NoSuchMethodException300{301test_athrow8();302}303304public static void test_athrow8() throws NullPointerException, NoSuchMethodException305{306test_throw_nosuchmethod();307}308}309310311