Path: blob/master/test/hotspot/jtreg/vmTestbase/jit/deoptimization/test04/test04.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/test04.27* VM Testbase keywords: [jit, quick]28*29* @library /vmTestbase30* /test/lib31* @run main/othervm jit.deoptimization.test04.test0432*/3334package jit.deoptimization.test04;3536import nsk.share.TestFailure;3738/*39*40*/4142public class test04 {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 int foo(int index) {61int rv = ++count;62if (index < A.sIndex / 2)63rv = index;64else {65try {66rv = ((A)Class.forName("jit.deoptimization.test04.B").newInstance()).foo(index);67}68catch(Exception e) {69}70}71return rv;72}7374public 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 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.test04.C").newInstance()).foo(index);93else94rv = ((B)Class.forName("jit.deoptimization.test04.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 int foo(int index) {112int j = count;113for (int i=0; i<500; i++)114j += used_alot();115return j;116}117118public int used_alot() {119int i=1;120int j=4;121int k=i+j;122byte ba[] = new byte[1000];123int ia[] = new int[1000];124return this.count + (ba.length + i + j - k - ia.length);125}126127protected int count = 1;128}129130class D extends C {131public D () {132super();133134this.count+=2;135}136137public int foo(int index) {138return super.foo(index);139}140141public synchronized int used_alot() {142count += (--count);143return 0;144}145}146147148