Path: blob/master/test/hotspot/jtreg/vmTestbase/jit/deoptimization/test05/test05.java
40948 views
/*1* Copyright (c) 2008, 2020, 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*26* @summary converted from VM Testbase jit/deoptimization/test05.27* VM Testbase keywords: [jit, quick]28*29* @library /vmTestbase30* /test/lib31* @run main/othervm jit.deoptimization.test05.test0532*/3334package jit.deoptimization.test05;3536import nsk.share.TestFailure;3738/*39*40*/4142public class test05 {43public static void main (String[] args) {44A obj = new A();4546int result = -1;47for (int index = 0; index < 1; index++) {48result += obj.used_alot();49}5051if (result != -1) {52throw new TestFailure("result : " + result + " must equal 1");53}54}55}565758class A {59protected int count;60public synchronized int foo(int index) {61int rv = ++count;62if (index < A.sIndex / 2)63rv = index;64else {65try {66rv = ((A)Class.forName("jit.deoptimization.test05.B").newInstance()).foo(index);67}68catch(Exception e) {69}70}71return rv;72}7374public synchronized int used_alot() {75int result = 1;76for (int i = 0; i < A.sIndex; i++) {77result = foo(i);78}79return result;80}8182protected static final int sIndex = 25000;83}8485class B extends A {86public synchronized int foo(int index) {87int rv = 0;88int qrtr = A.sIndex / 4;89if (index > 3 * qrtr) {90try {91if (index < A.sIndex - qrtr)92rv = ((B)Class.forName("jit.deoptimization.test05.C").newInstance()).foo(index);93else94rv = ((B)Class.forName("jit.deoptimization.test05.D").newInstance()).foo(index);95}96catch(Exception e) {97}98}99else {100rv = 1;101}102return rv;103}104}105106class C extends B {107public C () {108--this.count;109}110111public synchronized int foo(int index) {112int j = count;113for (int i=0; i<5000; i++) {114j += used_alot();115116if (i==4999) {117try {118j = ((D2)Class.forName("jit.deoptimization.test05.D2").newInstance()).foo(index);119}120catch (Exception e) {}121}122}123return j;124}125126public synchronized int used_alot() {127int i=1;128int j=4;129int k=i+j;130byte ba[] = new byte[1000];131int ia[] = new int[1000];132return this.count + (ba.length + i + j - k - ia.length);133}134135protected int count = 1;136}137138class D extends C {139public D () {140super();141142this.count+=2;143}144145public int foo(int index) {146return super.foo(index);147}148149public synchronized int used_alot() {150count += (--count);151return 0;152}153}154155class D2 extends C {156public int foo(int index) {157return 0;158}159}160161162