Path: blob/master/test/hotspot/jtreg/vmTestbase/vm/compiler/coverage/parentheses/Parentheses.java
41161 views
/*1* Copyright (c) 2012, 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*/22package vm.compiler.coverage.parentheses;2324import vm.compiler.coverage.parentheses.share.HotspotInstructionsExecutor;25import vm.share.options.Option;26import vm.share.options.Options;27import vm.share.options.OptionSupport;2829import nsk.share.Failure;30import nsk.share.Log;31import nsk.share.test.StressOptions;3233import vm.compiler.coverage.parentheses.share.InstructionSequence;34import vm.compiler.coverage.parentheses.share.TinyInstructionsExecutor;35import vm.compiler.coverage.parentheses.share.generation.RandomInstructionsGenerator;3637import java.io.IOException;3839public class Parentheses {4041private Log log;4243@Option(name = "iterations", default_value = "100", description = "number of iterations")44int iterations = 2000;4546@Option(name = "maxStackDepth", default_value = "100",47description = "maximal stack depth that can be required by generated instruction sequence")48int maxStackDepth = 100;4950@Options51StressOptions stressOptions = new StressOptions();5253@Option(name = "verbose", default_value = "false", description = "verbose mode")54boolean verbose;5556@Option(name = "loadFrom", default_value = "", description = "path to file that contains instruction sequence")57String loadFrom = "";5859@Option(name = "saveTo", default_value = "parentheses",60description = "path to file in which will be stored instruction sequence if errors will be occur")61String saveTo = "saveTo";6263public static void main(String[] args) throws Exception {64Parentheses test = new Parentheses();65OptionSupport.setup(test, args);66test.run();67}6869public void run() throws IOException, ReflectiveOperationException {7071log = new Log(System.out, verbose);7273InstructionSequence instructionSequence = null;74for (int i = 0; i < iterations * stressOptions.getIterationsFactor(); i++) {75log.display("Iteration " + i);76if (loadFrom.isEmpty()) {77log.display("generating instructions list");78instructionSequence = new RandomInstructionsGenerator(maxStackDepth).generate();79} else {80if (instructionSequence == null) {81log.display("loading instructions list from file: " + loadFrom);82instructionSequence = InstructionSequence.fromFile(loadFrom);83}84}8586log.display("executing instructions");8788TinyInstructionsExecutor tinyVM = new TinyInstructionsExecutor(instructionSequence.getMaxStackDepth());89int tinyRes = tinyVM.execute(instructionSequence.getInstructions());9091HotspotInstructionsExecutor hotspot = new HotspotInstructionsExecutor(instructionSequence.getMaxStackDepth());92int hotspotRes = hotspot.execute(instructionSequence.getInstructions());9394if (tinyRes != hotspotRes) {95log.complain("Incorrect results of InstructionsExecutor instructions computations");96log.complain("instructions:");97log.complain(instructionSequence.toString());98log.complain("TinyInstructionsExecutor result: " + tinyRes);99log.complain("HotspotInstructionsExecutor result: " + hotspotRes);100log.complain("Instruction sequence was written to file: " + saveTo);101instructionSequence.saveToFile(saveTo);102throw new Failure("Incorrect results of InstructionsExecutor instructions computations");103} else {104log.display("TinyInstructionsExecutor result: " + tinyRes);105log.display("HotspotInstructionsExecutor result: " + hotspotRes);106log.display("");107}108}109110}111}112113114