Path: blob/master/test/hotspot/jtreg/vmTestbase/jit/graph/test6.java
40948 views
/*1* Copyright (c) 2008, 2021, 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 jit.graph;2425import jdk.test.lib.Utils;26import nsk.share.TestFailure;2728import java.lang.reflect.InvocationTargetException;29import java.util.Random;30import java.util.Vector;3132public class test6 {33private static final int[] MethodID = {Globals.MethodID_Array[11]};3435private static Random localNumGen = new Random(Utils.SEED);36private static final int maxEntries = 25;3738// flattens the binary tree into an array39private void getSortedArray(Node root, int[] dataArray, int[] index) {40if ((root != null) && (root != RBTree.treeNull)) {41getSortedArray(root.getNode(Node.Left_son), dataArray, index);42dataArray[index[0]++] = root.getKey();43getSortedArray(root.getNode(Node.Right_son), dataArray, index);44}45}4647public synchronized void rbTest(Vector summation, Vector ID, Long functionDepth, Integer staticFunctionDepth)48throws InvocationTargetException {49Globals.appendSumToSummationVector(MethodID[0], summation);5051if (CGT.shouldFinish()) {52return;53}54if (Globals.VERBOSE) {55System.out.println("test6.rbTest");56}5758if ((functionDepth.longValue() <= 0) && (staticFunctionDepth.intValue() <= 0)) {59return;60}61MethodData methodCallStr;62Long numFcalls;63Integer staticFcalls;6465if (staticFunctionDepth.intValue() > 0) {66numFcalls = functionDepth;67staticFcalls = Integer.valueOf(staticFunctionDepth.intValue() - 1);68methodCallStr = Globals.returnNextStaticMethod(MethodID[0]);69} else {70numFcalls = Long.valueOf(functionDepth.longValue() - 1);71staticFcalls = staticFunctionDepth;72methodCallStr = Globals.nextRandomMethod();73}7475RBTree myTree = new RBTree();76int numElements = 1 + localNumGen.nextInt(maxEntries);77int dataArray[] = new int[numElements];78boolean insertArray[] = new boolean[numElements];7980Vector temp = new Vector(numElements);81// code guarantees no duplicates82for (int i = 0; i < numElements; i++) {83int nextKey = localNumGen.nextInt(16385);84while (temp.indexOf(Integer.valueOf(nextKey)) != -1) {85nextKey = localNumGen.nextInt(16385);86}8788temp.addElement(Integer.valueOf(nextKey));89dataArray[i] = nextKey;9091insertArray[i] = false;92}93temp = null;9495int numLoops = 10 + localNumGen.nextInt(1024);96for (int i = 0; i < numLoops; i++) {97int nextIndex = localNumGen.nextInt(numElements);98if (!insertArray[nextIndex]) {99myTree.RBInsert(dataArray[nextIndex]);100insertArray[nextIndex] = true;101} else {102myTree.RBDelete(dataArray[nextIndex]);103insertArray[nextIndex] = false;104}105}106107int numValid = 0;108for (int i = 0; i < numElements; i++) {109Node searchNode = myTree.Search(dataArray[i]);110if (insertArray[i] && (searchNode == RBTree.treeNull)) {111throw new TestFailure("Valid Node Not Found in Binary Tree. Node " + dataArray[i]);112} else if ((!insertArray[i]) && (searchNode != RBTree.treeNull)) {113throw new TestFailure("Deleted Node Found in Binary Tree. Node " + dataArray[i]);114} else if (insertArray[i]) {115numValid++;116}117// so that verification is only done once118insertArray[i] = true;119}120121int[] sortedArray = new int[numValid];122getSortedArray(myTree.getRoot(), sortedArray, new int[]{0});123124for (int i = 1; i < numValid; i++) {125if (sortedArray[i] <= sortedArray[i - 1]) {126StringBuilder outStr = new StringBuilder("Actual ");127for (int aSortedArray : sortedArray) {128outStr.append(aSortedArray)129.append(", ");130}131System.out.println("Binary Tree Property Not Held");132System.out.println("Root " + myTree.getRoot()133.getKey());134throw new TestFailure(outStr.toString());135}136}137138Globals.addFunctionIDToVector(methodCallStr.id, ID);139Globals.callMethod(methodCallStr, summation, ID, numFcalls, staticFcalls);140}141}142143144