# HG changeset patch # User ppunegov # Date 1444752110 -10800 # Tue Oct 13 19:01:50 2015 +0300 # Node ID b6b897b6e6808a91ec59a25116c521389d16fdc7 # Parent f2983a0f7a57c369d87fbbe16244a7bfa6ebc861 [mq]: existing-directives diff --git a/test/compiler/compilercontrol/commandfile/CompileOnlyTest.java b/test/compiler/compilercontrol/commandfile/CompileOnlyTest.java new file mode 100644 --- /dev/null +++ b/test/compiler/compilercontrol/commandfile/CompileOnlyTest.java @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/* + * @test + * @bug 8137167 + * @summary Tests CompileCommand=compileonly + * @library /testlibrary /../../test/lib /compiler/testlibrary ../share / + * @build CompileOnlyTest pool.sub.* pool.subpack.* sun.hotspot.WhiteBox + * compiler.testlibrary.CompilerUtils compiler.compilercontrol.share.actions.* + * @run main ClassFileInstaller sun.hotspot.WhiteBox + * sun.hotspot.WhiteBox$WhiteBoxPermission + * @run main/othervm compiler.compilercontrol.commandfile.CompileOnlyTest + */ + +package compiler.compilercontrol.commandfile; + +import compiler.compilercontrol.share.SingleCommand; +import compiler.compilercontrol.share.scenario.Command; +import compiler.compilercontrol.share.scenario.Scenario; + +public class CompileOnlyTest { + public static void main(String[] args) { + new SingleCommand(Command.COMPILEONLY, Scenario.Type.FILE).test(); + } +} diff --git a/test/compiler/compilercontrol/commandfile/ExcludeTest.java b/test/compiler/compilercontrol/commandfile/ExcludeTest.java new file mode 100644 --- /dev/null +++ b/test/compiler/compilercontrol/commandfile/ExcludeTest.java @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/* + * @test + * @bug 8137167 + * @summary Tests CompileCommand=exclude + * @library /testlibrary /../../test/lib /compiler/testlibrary ../share / + * @build ExcludeTest pool.sub.* pool.subpack.* sun.hotspot.WhiteBox + * compiler.testlibrary.CompilerUtils compiler.compilercontrol.share.actions.* + * @run main ClassFileInstaller sun.hotspot.WhiteBox + * sun.hotspot.WhiteBox$WhiteBoxPermission + * @run main/othervm compiler.compilercontrol.commands.ExcludeTest + */ + +package compiler.compilercontrol.commandfile; + +import compiler.compilercontrol.share.SingleCommand; +import compiler.compilercontrol.share.scenario.Command; +import compiler.compilercontrol.share.scenario.Scenario; + +public class ExcludeTest { + public static void main(String[] args) { + new SingleCommand(Command.EXCLUDE, Scenario.Type.FILE).test(); + } +} diff --git a/test/compiler/compilercontrol/commandfile/LogTest.java b/test/compiler/compilercontrol/commandfile/LogTest.java new file mode 100644 --- /dev/null +++ b/test/compiler/compilercontrol/commandfile/LogTest.java @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/* + * @test + * @bug 8137167 + * @summary Tests CompileCommand=log + * @library /testlibrary /../../test/lib /compiler/testlibrary ../share / + * @build LogTest pool.sub.* pool.subpack.* sun.hotspot.WhiteBox + * compiler.testlibrary.CompilerUtils compiler.compilercontrol.share.actions.* + * @run main ClassFileInstaller sun.hotspot.WhiteBox + * sun.hotspot.WhiteBox$WhiteBoxPermission + * @run main/othervm compiler.compilercontrol.commandfile.LogTest + */ + +package compiler.compilercontrol.commandfile; + +import compiler.compilercontrol.share.SingleCommand; +import compiler.compilercontrol.share.scenario.Command; +import compiler.compilercontrol.share.scenario.Scenario; + +public class LogTest { + public static void main(String[] args) { + new SingleCommand(Command.LOG, Scenario.Type.FILE).test(); + } +} diff --git a/test/compiler/compilercontrol/commandfile/PrintTest.java b/test/compiler/compilercontrol/commandfile/PrintTest.java new file mode 100644 --- /dev/null +++ b/test/compiler/compilercontrol/commandfile/PrintTest.java @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/* + * @test + * @bug 8137167 + * @summary Tests CompileCommand=print + * @library /testlibrary /../../test/lib /compiler/testlibrary ../share / + * @build PrintTest pool.sub.* pool.subpack.* sun.hotspot.WhiteBox + * compiler.testlibrary.CompilerUtils compiler.compilercontrol.share.actions.* + * @run main ClassFileInstaller sun.hotspot.WhiteBox + * sun.hotspot.WhiteBox$WhiteBoxPermission + * @run main/othervm compiler.compilercontrol.commandfile.PrintTest + */ + +package compiler.compilercontrol.commandfile; + +import compiler.compilercontrol.share.SingleCommand; +import compiler.compilercontrol.share.scenario.Command; +import compiler.compilercontrol.share.scenario.Scenario; + +public class PrintTest { + public static void main(String[] args) { + new SingleCommand(Command.PRINT, Scenario.Type.FILE).test(); + } +} diff --git a/test/compiler/compilercontrol/commands/CompileOnlyTest.java b/test/compiler/compilercontrol/commands/CompileOnlyTest.java new file mode 100644 --- /dev/null +++ b/test/compiler/compilercontrol/commands/CompileOnlyTest.java @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/* + * @test + * @bug 8137167 + * @summary Tests CompileCommand=compileonly + * @library /testlibrary /../../test/lib /compiler/testlibrary ../share / + * @build CompileOnlyTest pool.sub.* pool.subpack.* sun.hotspot.WhiteBox + * compiler.testlibrary.CompilerUtils compiler.compilercontrol.share.actions.* + * @run main ClassFileInstaller sun.hotspot.WhiteBox + * sun.hotspot.WhiteBox$WhiteBoxPermission + * @run main/othervm compiler.compilercontrol.commands.CompileOnlyTest + */ + +package compiler.compilercontrol.commands; + +import compiler.compilercontrol.share.SingleCommand; +import compiler.compilercontrol.share.scenario.Command; +import compiler.compilercontrol.share.scenario.Scenario; + +public class CompileOnlyTest { + public static void main(String[] args) { + new SingleCommand(Command.COMPILEONLY, Scenario.Type.OPTION).test(); + } +} diff --git a/test/compiler/compilercontrol/commands/ExcludeTest.java b/test/compiler/compilercontrol/commands/ExcludeTest.java new file mode 100644 --- /dev/null +++ b/test/compiler/compilercontrol/commands/ExcludeTest.java @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/* + * @test + * @bug 8137167 + * @summary Tests CompileCommand=exclude + * @library /testlibrary /../../test/lib /compiler/testlibrary ../share / + * @build ExcludeTest pool.sub.* pool.subpack.* sun.hotspot.WhiteBox + * compiler.testlibrary.CompilerUtils compiler.compilercontrol.share.actions.* + * @run main ClassFileInstaller sun.hotspot.WhiteBox + * sun.hotspot.WhiteBox$WhiteBoxPermission + * @run main/othervm compiler.compilercontrol.commands.ExcludeTest + */ + +package compiler.compilercontrol.commands; + +import compiler.compilercontrol.share.SingleCommand; +import compiler.compilercontrol.share.scenario.Command; +import compiler.compilercontrol.share.scenario.Scenario; + +public class ExcludeTest { + public static void main(String[] args) { + new SingleCommand(Command.EXCLUDE, Scenario.Type.OPTION).test(); + } +} diff --git a/test/compiler/compilercontrol/commands/LogTest.java b/test/compiler/compilercontrol/commands/LogTest.java new file mode 100644 --- /dev/null +++ b/test/compiler/compilercontrol/commands/LogTest.java @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/* + * @test + * @bug 8137167 + * @summary Tests CompileCommand=log + * @library /testlibrary /../../test/lib /compiler/testlibrary ../share / + * @build LogTest pool.sub.* pool.subpack.* sun.hotspot.WhiteBox + * compiler.testlibrary.CompilerUtils compiler.compilercontrol.share.actions.* + * @run main ClassFileInstaller sun.hotspot.WhiteBox + * sun.hotspot.WhiteBox$WhiteBoxPermission + * @run main/othervm compiler.compilercontrol.commands.LogTest + */ + +package compiler.compilercontrol.commands; + +import compiler.compilercontrol.share.SingleCommand; +import compiler.compilercontrol.share.scenario.Command; +import compiler.compilercontrol.share.scenario.Scenario; + +public class LogTest { + public static void main(String[] args) { + new SingleCommand(Command.LOG, Scenario.Type.OPTION).test(); + } +} diff --git a/test/compiler/compilercontrol/commands/PrintTest.java b/test/compiler/compilercontrol/commands/PrintTest.java new file mode 100644 --- /dev/null +++ b/test/compiler/compilercontrol/commands/PrintTest.java @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/* + * @test + * @bug 8137167 + * @summary Tests CompileCommand=print + * @library /testlibrary /../../test/lib /compiler/testlibrary ../share / + * @build PrintTest pool.sub.* pool.subpack.* sun.hotspot.WhiteBox + * compiler.testlibrary.CompilerUtils compiler.compilercontrol.share.actions.* + * @run main ClassFileInstaller sun.hotspot.WhiteBox + * sun.hotspot.WhiteBox$WhiteBoxPermission + * @run main/othervm compiler.compilercontrol.commands.PrintTest + */ + +package compiler.compilercontrol.commands; + +import compiler.compilercontrol.share.SingleCommand; +import compiler.compilercontrol.share.scenario.Command; +import compiler.compilercontrol.share.scenario.Scenario; + +public class PrintTest { + public static void main(String[] args) { + new SingleCommand(Command.PRINT, Scenario.Type.OPTION).test(); + } +} diff --git a/test/compiler/compilercontrol/directives/CompileOnlyTest.java b/test/compiler/compilercontrol/directives/CompileOnlyTest.java new file mode 100644 --- /dev/null +++ b/test/compiler/compilercontrol/directives/CompileOnlyTest.java @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/* + * @test + * @bug 8137167 + * @summary Tests directives to be able to compile only specified methods + * @library /testlibrary /../../test/lib /compiler/testlibrary ../share / + * @build CompileOnlyTest pool.sub.* pool.subpack.* sun.hotspot.WhiteBox + * compiler.testlibrary.CompilerUtils compiler.compilercontrol.share.actions.* + * @run main ClassFileInstaller sun.hotspot.WhiteBox + * sun.hotspot.WhiteBox$WhiteBoxPermission + * @run main/othervm compiler.compilercontrol.directives.CompileOnlyTest + */ + +package compiler.compilercontrol.directives; + +import compiler.compilercontrol.share.SingleCommand; +import compiler.compilercontrol.share.scenario.Command; +import compiler.compilercontrol.share.scenario.Scenario; + +public class CompileOnlyTest { + public static void main(String[] args) { + new SingleCommand(Command.COMPILEONLY, Scenario.Type.DIRECTIVE) + .test(); + } +} diff --git a/test/compiler/compilercontrol/directives/ExcludeTest.java b/test/compiler/compilercontrol/directives/ExcludeTest.java new file mode 100644 --- /dev/null +++ b/test/compiler/compilercontrol/directives/ExcludeTest.java @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/* + * @test + * @bug 8137167 + * @summary Tests directives to be able to exclude methods from compilation + * @library /testlibrary /../../test/lib /compiler/testlibrary ../share / + * @build ExcludeTest pool.sub.* pool.subpack.* sun.hotspot.WhiteBox + * compiler.testlibrary.CompilerUtils compiler.compilercontrol.share.actions.* + * @run main ClassFileInstaller sun.hotspot.WhiteBox + * sun.hotspot.WhiteBox$WhiteBoxPermission + * @run main/othervm compiler.compilercontrol.directives.ExcludeTest + */ + +package compiler.compilercontrol.directives; + +import compiler.compilercontrol.share.SingleCommand; +import compiler.compilercontrol.share.scenario.Command; +import compiler.compilercontrol.share.scenario.Scenario; + +public class ExcludeTest { + public static void main(String[] args) { + new SingleCommand(Command.EXCLUDE, Scenario.Type.DIRECTIVE).test(); + } +} diff --git a/test/compiler/compilercontrol/directives/LogTest.java b/test/compiler/compilercontrol/directives/LogTest.java new file mode 100644 --- /dev/null +++ b/test/compiler/compilercontrol/directives/LogTest.java @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/* + * @test + * @bug 8137167 + * @summary Tests directives to be able to turn on LogCompilation + * @library /testlibrary /../../test/lib /compiler/testlibrary ../share / + * @build LogTest pool.sub.* pool.subpack.* sun.hotspot.WhiteBox + * compiler.testlibrary.CompilerUtils compiler.compilercontrol.share.actions.* + * @run main ClassFileInstaller sun.hotspot.WhiteBox + * sun.hotspot.WhiteBox$WhiteBoxPermission + * @run main/othervm compiler.compilercontrol.directives.LogTest + */ + +package compiler.compilercontrol.directives; + +import compiler.compilercontrol.share.SingleCommand; +import compiler.compilercontrol.share.scenario.Command; +import compiler.compilercontrol.share.scenario.Scenario; + +public class LogTest { + public static void main(String[] args) { + new SingleCommand(Command.LOG, Scenario.Type.DIRECTIVE).test(); + } +} diff --git a/test/compiler/compilercontrol/directives/PrintTest.java b/test/compiler/compilercontrol/directives/PrintTest.java new file mode 100644 --- /dev/null +++ b/test/compiler/compilercontrol/directives/PrintTest.java @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/* + * @test + * @bug 8137167 + * @summary Tests directives to be able to turn on print_assembly + * @library /testlibrary /../../test/lib /compiler/testlibrary ../share / + * @build PrintTest pool.sub.* pool.subpack.* sun.hotspot.WhiteBox + * compiler.testlibrary.CompilerUtils compiler.compilercontrol.share.actions.* + * @run main ClassFileInstaller sun.hotspot.WhiteBox + * sun.hotspot.WhiteBox$WhiteBoxPermission + * @run main/othervm compiler.compilercontrol.directives.PrintTest + */ + +package compiler.compilercontrol.directives; + +import compiler.compilercontrol.share.SingleCommand; +import compiler.compilercontrol.share.scenario.Command; +import compiler.compilercontrol.share.scenario.Scenario; + +public class PrintTest { + public static void main(String[] args) { + new SingleCommand(Command.PRINT, Scenario.Type.DIRECTIVE).test(); + } +} diff --git a/test/compiler/compilercontrol/mixed/RandomCommandsTest.java b/test/compiler/compilercontrol/mixed/RandomCommandsTest.java new file mode 100644 --- /dev/null +++ b/test/compiler/compilercontrol/mixed/RandomCommandsTest.java @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/* + * @test + * @bug 8137167 + * @summary Randomly generates commands with random types + * @library /testlibrary /../../test/lib /compiler/testlibrary ../share / + * @build RandomCommandsTest pool.sub.* pool.subpack.* sun.hotspot.WhiteBox + * compiler.testlibrary.CompilerUtils compiler.compilercontrol.share.actions.* + * @run main ClassFileInstaller sun.hotspot.WhiteBox + * sun.hotspot.WhiteBox$WhiteBoxPermission + * @run main/othervm/timeout=600 compiler.compilercontrol.mixed.RandomCommandsTest + */ + +package compiler.compilercontrol.mixed; + +import compiler.compilercontrol.share.MultiCommand; + +public class RandomCommandsTest { + public static void main(String[] args) { + MultiCommand.generateRandomTest(false).test(); + } +} diff --git a/test/compiler/compilercontrol/mixed/RandomValidCommandsTest.java b/test/compiler/compilercontrol/mixed/RandomValidCommandsTest.java new file mode 100644 --- /dev/null +++ b/test/compiler/compilercontrol/mixed/RandomValidCommandsTest.java @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/* + * @test + * @bug 8137167 + * @summary Randomly generates valid commands with random types + * @library /testlibrary /../../test/lib /compiler/testlibrary ../share / + * @build RandomValidCommandsTest pool.sub.* pool.subpack.* sun.hotspot.WhiteBox + * compiler.testlibrary.CompilerUtils compiler.compilercontrol.share.actions.* + * @run main ClassFileInstaller sun.hotspot.WhiteBox + * sun.hotspot.WhiteBox$WhiteBoxPermission + * @run main/othervm/timeout=600 compiler.compilercontrol.mixed.RandomValidCommandsTest + */ + +package compiler.compilercontrol.mixed; + +import compiler.compilercontrol.share.MultiCommand; + +public class RandomValidCommandsTest { + public static void main(String[] args) { + MultiCommand.generateRandomTest(true).test(); + } +} diff --git a/test/compiler/compilercontrol/share/AbstractTestBase.java b/test/compiler/compilercontrol/share/AbstractTestBase.java new file mode 100644 --- /dev/null +++ b/test/compiler/compilercontrol/share/AbstractTestBase.java @@ -0,0 +1,60 @@ +/* + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package compiler.compilercontrol.share; + +import compiler.compilercontrol.share.method.MethodDescriptor; +import compiler.compilercontrol.share.method.MethodGenerator; +import jdk.test.lib.Pair; +import pool.PoolHelper; + +import java.lang.reflect.Executable; +import java.util.List; +import java.util.concurrent.Callable; + +public abstract class AbstractTestBase { + protected static final MethodGenerator METHOD_GEN = new MethodGenerator(); + protected static final int ATTEMPTS = 25; + protected static final List>> METHODS + = new PoolHelper().getAllMethods(PoolHelper.METHOD_FILTER); + + public abstract void test(); + + /** + * Generate random valid method descriptor + * + * @param exec method to make descriptor for + * @return a valid {@link MethodDescriptor#isValid()} descriptor instance + */ + public static MethodDescriptor getValidMethodDescriptor(Executable exec) { + MethodDescriptor md = METHOD_GEN.generateRandomDescriptor(exec); + for (int i = 0; !md.isValid() && i < ATTEMPTS; i++) { + md = METHOD_GEN.generateRandomDescriptor(exec); + } + if (!md.isValid()) { + System.out.println("WARN: Using predefined pattern"); + md = MethodGenerator.commandDescriptor(exec); + } + return md; + } +} diff --git a/test/compiler/compilercontrol/share/JSONFile.java b/test/compiler/compilercontrol/share/JSONFile.java new file mode 100644 --- /dev/null +++ b/test/compiler/compilercontrol/share/JSONFile.java @@ -0,0 +1,189 @@ +/* + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package compiler.compilercontrol.share; + +import java.io.FileNotFoundException; +import java.io.PrintStream; +import java.util.Objects; +import java.util.Stack; + +/** + * Simple JSON file writer + */ +public class JSONFile implements AutoCloseable { + private final Stack stack; + private final String fileName; + private final PrintStream out; + private int spaces; + + /** + * JSON element + */ + public enum Element { + OBJECT, + ARRAY, + PAIR, + VALUE + } + + /** + * Constructor. Creates file with default name + */ + public JSONFile() { + this("directives_file.json"); + } + + /** + * Constructor + * + * @param fileName file name + */ + public JSONFile(String fileName) { + this.spaces = 0; + this.stack = new Stack<>(); + this.fileName = fileName; + try { + out = new PrintStream(fileName); + } catch (FileNotFoundException e) { + throw new Error("TESTBUG: can't open/create file " + fileName, e); + } + } + + /** + * Gets file name + * + * @return file name string + */ + public String getFileName() { + return fileName; + } + + /** + * Gets current JSON element in the file. + * The element is a current {@linkplain Element} + * that was written into a file. + * + * @return the type of the current element, + * or null if there are nothing written + */ + public Element getElement() { + if (stack.empty()) { + return null; + } + return stack.peek(); + } + + /** + * Writes given type with a value to file. + * Note that only PAIR and VALUE types accept a single value parameter. + * OBJECT and ARRAY do not have a value + * + * @param element JSON element type + * @param value element's value + * @return this file instance + */ + public JSONFile write(Element element, String... value) { + if (value.length > 1) { + throw new Error("TESTBUG: Unexpected value length: " + + value.length); + } + if (!stack.empty()) { + if (stack.peek() == Element.VALUE) { + out.print(", "); + stack.pop(); + } + } + switch (element) { + case OBJECT: + out.print("{"); + spaces++; + stack.push(Element.VALUE); + break; + case ARRAY: + out.print("["); + stack.push(Element.VALUE); + break; + case PAIR: + fillSpaces(); + Objects.requireNonNull(value, "TESTBUG: " + element + + "requires a value to be set"); + out.print(value[0] + ": "); + break; + case VALUE: + Objects.requireNonNull(value, "TESTBUG: " + element + + "requires a value to be set"); + out.print(value[0]); + break; + } + stack.push(element); + return this; + } + + private void fillSpaces() { + out.println(); + for (int i = 0; i < spaces; i++) { + // Fill with spaces to be more readable + out.print(" "); + } + } + + /** + * Ends current object or array of {@linkplain Element} + * + * @return this file instance + */ + public JSONFile end() { + if (!stack.empty()) { + Element prev = stack.pop(); + while (prev != Element.OBJECT && prev != Element.ARRAY + && !stack.empty()) { + prev = stack.pop(); + } + switch (prev) { + case OBJECT: + spaces--; + fillSpaces(); + out.print("}"); + break; + case ARRAY: + out.print("]"); + break; + default: + throw new Error("TESTBUG: Incorrect end. " + + "Wrong type found: " + prev); + } + } else { + throw new Error("TESTBUG: Incorrect end. Empty stack"); + } + return this; + } + + /** + * Closes this file + */ + @Override + public void close() { + out.close(); + } +} diff --git a/test/compiler/compilercontrol/share/MultiCommand.java b/test/compiler/compilercontrol/share/MultiCommand.java new file mode 100644 --- /dev/null +++ b/test/compiler/compilercontrol/share/MultiCommand.java @@ -0,0 +1,82 @@ +/* + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package compiler.compilercontrol.share; + +import compiler.compilercontrol.share.method.MethodDescriptor; +import compiler.compilercontrol.share.scenario.Command; +import compiler.compilercontrol.share.scenario.CommandGenerator; +import compiler.compilercontrol.share.scenario.CompileCommand; +import compiler.compilercontrol.share.scenario.Scenario; +import jdk.test.lib.Utils; + +import java.lang.reflect.Executable; +import java.util.ArrayList; +import java.util.List; + +public class MultiCommand extends AbstractTestBase { + private final List testCases; + + public MultiCommand(List testCases) { + this.testCases = testCases; + } + + /** + * Generates a test containing multiple random commands + * + * @param validOnly shows that all commands should be valid + * @return test instance to run + */ + public static AbstractTestBase generateRandomTest(boolean validOnly) { + CommandGenerator cmdGen = new CommandGenerator(); + List commands = cmdGen.generateCommands(); + List testCases = new ArrayList<>(); + for (Command cmd : commands) { + if (validOnly && cmd == Command.NONEXISTENT) { + // skip invalid command + continue; + } + Executable exec = Utils.getRandomElement(METHODS).first; + MethodDescriptor md; + if (validOnly) { + md = AbstractTestBase.getValidMethodDescriptor(exec); + } else { + md = AbstractTestBase.METHOD_GEN.generateRandomDescriptor(exec); + } + CompileCommand cc = cmdGen.generateCompileCommand(cmd, md, null); + testCases.add(cc); + } + return new MultiCommand(testCases); + } + + @Override + public void test() { + Scenario.Builder builder = Scenario.getBuilder(); + for (CompileCommand cc : testCases) { + cc.print(); + builder.add(cc); + } + Scenario scenario = builder.build(); + scenario.execute(); + } +} diff --git a/test/compiler/compilercontrol/share/SingleCommand.java b/test/compiler/compilercontrol/share/SingleCommand.java new file mode 100644 --- /dev/null +++ b/test/compiler/compilercontrol/share/SingleCommand.java @@ -0,0 +1,57 @@ +/* + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package compiler.compilercontrol.share; + +import compiler.compilercontrol.share.method.MethodDescriptor; +import compiler.compilercontrol.share.scenario.Command; +import compiler.compilercontrol.share.scenario.CommandGenerator; +import compiler.compilercontrol.share.scenario.CompileCommand; +import compiler.compilercontrol.share.scenario.Scenario; +import jdk.test.lib.Utils; + +import java.lang.reflect.Executable; + +public class SingleCommand extends AbstractTestBase { + private final Command command; + private final Scenario.Type type; + + public SingleCommand(Command command, Scenario.Type type) { + this.command = command; + this.type = type; + } + + @Override + public void test() { + Scenario.Builder builder = Scenario.getBuilder(); + Executable exec = Utils.getRandomElement(METHODS).first; + MethodDescriptor md = getValidMethodDescriptor(exec); + CommandGenerator cmdGen = new CommandGenerator(); + CompileCommand compileCommand = cmdGen.generateCompileCommand(command, + md, type); + compileCommand.print(); + builder.add(compileCommand); + Scenario scenario = builder.build(); + scenario.execute(); + } +} diff --git a/test/compiler/compilercontrol/share/actions/BaseAction.java b/test/compiler/compilercontrol/share/actions/BaseAction.java new file mode 100644 --- /dev/null +++ b/test/compiler/compilercontrol/share/actions/BaseAction.java @@ -0,0 +1,123 @@ +/* + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package compiler.compilercontrol.share.actions; + +import compiler.compilercontrol.share.scenario.State; +import jdk.test.lib.Pair; +import jdk.test.lib.ProcessTools; +import pool.PoolHelper; + +import java.io.BufferedReader; +import java.io.InputStreamReader; +import java.io.PrintWriter; +import java.io.OutputStreamWriter; +import java.io.IOException; +import java.lang.reflect.Executable; +import java.net.InetAddress; +import java.net.Socket; +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.ListIterator; +import java.util.Map; +import java.util.concurrent.Callable; +import java.util.stream.Collectors; + +public class BaseAction { + private static final List>> METHODS; + private static final Map METHODS_NAMES; + + static { + METHODS = new PoolHelper().getAllMethods(); + METHODS_NAMES = METHODS.stream().collect(Collectors.toMap( + pair -> pair.first.toGenericString(), + pair -> pair.first)); + } + + public static void main(String[] args) { + if (args.length < 1) { + throw new Error("TESTBUG: requires port as parameter: " + + Arrays.toString(args)); + } + int pid; + try { + pid = ProcessTools.getProcessId(); + } catch (Exception e) { + throw new Error("Could not determine own pid", e); + } + int port = Integer.parseInt(args[0]); + System.out.println("INFO: Client connection port = " + port); + List lines; + try ( + Socket socket = new Socket(InetAddress.getLocalHost(), port); + BufferedReader in = new BufferedReader( + new InputStreamReader(socket.getInputStream())); + PrintWriter out = new PrintWriter( + new OutputStreamWriter(socket.getOutputStream()))) { + // send own pid to execute jcmd if needed + out.println(String.valueOf(pid)); + out.flush(); + lines = in.lines().collect(Collectors.toList()); + } catch (IOException e) { + throw new Error("Error on performing network operation", e); + } + check(decodeMap(lines)); + } + + private static Map decodeMap(List lines) { + if (lines == null || lines.size() == 0) { + throw new Error("TESTBUG: unexpected lines list"); + } + Map stateMap = new HashMap<>(); + int startIndex = 0; + ListIterator iterator = lines.listIterator(); + while (iterator.hasNext()) { + int index = iterator.nextIndex(); + String next = iterator.next(); + switch (next) { + case "{" : + startIndex = index; + break; + case "}" : + // method name goes after { + Executable executable = METHODS_NAMES.get(lines.get( + ++startIndex)); + // state description starts after method + State state = State.fromString(lines.subList(++startIndex, + index).toArray(new String[index - startIndex])); + stateMap.put(executable, state); + break; + } + } + return stateMap; + } + + protected static void check(Map methodStates) { + // Check each method from the pool + METHODS.forEach(pair -> { + Executable x = pair.first; + CompileAction.checkCompiled(x, methodStates.get(x)); + }); + } +} diff --git a/test/compiler/compilercontrol/share/actions/CompileAction.java b/test/compiler/compilercontrol/share/actions/CompileAction.java new file mode 100644 --- /dev/null +++ b/test/compiler/compilercontrol/share/actions/CompileAction.java @@ -0,0 +1,108 @@ +/* + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package compiler.compilercontrol.share.actions; + +import compiler.compilercontrol.share.scenario.State; +import compiler.testlibrary.CompilerUtils; +import jdk.test.lib.Asserts; +import jdk.test.lib.Pair; +import jdk.test.lib.Utils; +import pool.PoolHelper; +import sun.hotspot.WhiteBox; + +import java.lang.reflect.Executable; +import java.util.List; +import java.util.concurrent.Callable; + +public class CompileAction { + private static final WhiteBox WHITE_BOX = WhiteBox.getWhiteBox(); + private static final int[] COMP_LEVELS; + private static final List>> METHODS + = new PoolHelper().getAllMethods(); + private static final int EXEC_AMOUNT = 100; + + static { + COMP_LEVELS = CompilerUtils.getAvailableCompilationLevels(); + if (COMP_LEVELS.length == 0) { + throw new Error("TESTBUG: test requires JIT " + + "compiler to be available"); + } + } + + /** + * Checks executable if it could be compiled + * + * @param executable given executable to check + * @param state method compilation state + */ + public static void checkCompiled(Executable executable, + State state) { + int first = COMP_LEVELS[0]; + if (first < 4) { + checkCompilation(executable, first, state.isC1Compilable()); + } + int last = COMP_LEVELS[COMP_LEVELS.length - 1]; + if (last == 4) { + checkCompilation(executable, last, state.isC2Compilable()); + } + } + + private static void checkCompilation(Executable executable, + int level, + boolean expectedCompiled) { + execute(executable); + WHITE_BOX.enqueueMethodForCompilation(executable, level); + Utils.waitForCondition( + () -> { + execute(executable); + return !WHITE_BOX.isMethodQueuedForCompilation(executable); + }, 100L); + execute(executable); + boolean isCompiled = WHITE_BOX.isMethodCompiled(executable); + Asserts.assertEQ(isCompiled, expectedCompiled, + String.format("FAILED: method %s compiled: %b, but should: %b" + + " on required level: %d", executable, isCompiled, + expectedCompiled, level)); + } + + private static void execute(Executable executable) { + Callable callable = getCallableFor(executable); + try { + for (int i = 0; i < EXEC_AMOUNT; i++) { + callable.call(); + } + } catch (Exception e) { + throw new Error("Got exception during execution", e); + } + } + + private static Callable getCallableFor(Executable executable) { + for (Pair> pair : METHODS) { + if (pair.first == executable) { + return pair.second; + } + } + throw new Error("TESTBUG: wrong executable: " + executable); + } +} diff --git a/test/compiler/compilercontrol/share/method/MethodGenerator.java b/test/compiler/compilercontrol/share/method/MethodGenerator.java --- a/test/compiler/compilercontrol/share/method/MethodGenerator.java +++ b/test/compiler/compilercontrol/share/method/MethodGenerator.java @@ -124,6 +124,23 @@ } /** + * Method descriptor that matches any method. Its full signature is *.* + * + * @param executable executable used to generate descriptor + * @return MethodDescriptor instance + */ + public static MethodDescriptor anyMatchDescriptor(Executable executable) { + MethodDescriptor md = new MethodDescriptor(executable); + Combination patterns = new Combination<>(PatternType.ANY, + PatternType.ANY, PatternType.ANY); + md.aClass.setSeparator(Separator.SLASH); + md.aMethod.setSeparator(Separator.DOT); + md.aSignature.setSeparator(Separator.NONE); + md.setPatterns(patterns); + return md; + } + + /** * Generates a list of method patterns from the pool of methods * * @return a list of test cases diff --git a/test/compiler/compilercontrol/share/method/SignatureType.java b/test/compiler/compilercontrol/share/method/SignatureType.java --- a/test/compiler/compilercontrol/share/method/SignatureType.java +++ b/test/compiler/compilercontrol/share/method/SignatureType.java @@ -29,6 +29,7 @@ import java.lang.reflect.Executable; import java.lang.reflect.Method; import java.util.Arrays; +import java.util.regex.Pattern; /** * This class represents a signature of the method @@ -66,7 +67,8 @@ if (element.isEmpty()) { setPattern(MethodDescriptor.PatternType.ANY); } else { - super.setElement(element); + this.element = element; + this.regexp = element; } } @@ -148,4 +150,12 @@ + patternType); } } + + @Override + public String getRegexp() { + if ("\\(.*\\).*".equals(regexp)) { + return regexp; + } + return Pattern.quote(regexp); + } } diff --git a/test/compiler/compilercontrol/share/processors/CommandProcessor.java b/test/compiler/compilercontrol/share/processors/CommandProcessor.java new file mode 100644 --- /dev/null +++ b/test/compiler/compilercontrol/share/processors/CommandProcessor.java @@ -0,0 +1,62 @@ +/* + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package compiler.compilercontrol.share.processors; + +import compiler.compilercontrol.share.method.MethodDescriptor; +import compiler.compilercontrol.share.scenario.Command; +import compiler.compilercontrol.share.scenario.CompileCommand; +import jdk.test.lib.OutputAnalyzer; + +import java.util.List; +import java.util.function.Consumer; + +/** + * Checks that output contains a string with commands and full method pattern + */ +public class CommandProcessor implements Consumer { + protected final List commands; + + public CommandProcessor(List commands) { + this.commands = commands; + } + + @Override + public void accept(OutputAnalyzer outputAnalyzer) { + for (CompileCommand command : commands) { + MethodDescriptor methodDescriptor = command.methodDescriptor; + if (methodDescriptor.isValid()) { + Command cmd = command.command; + String method = methodDescriptor.getCanonicalString(); + outputAnalyzer.shouldContain("CompileCommand: " + cmd.name + + " " + method); + outputAnalyzer.shouldNotContain("CompileCommand: An error " + + "occurred during parsing"); + } else { + outputAnalyzer.shouldMatch("(CompileCommand: )" + + "(unrecognized command)|(Bad pattern)|" + + "(An error occurred during parsing)"); + } + } + } +} diff --git a/test/compiler/compilercontrol/share/processors/LogProcessor.java b/test/compiler/compilercontrol/share/processors/LogProcessor.java new file mode 100644 --- /dev/null +++ b/test/compiler/compilercontrol/share/processors/LogProcessor.java @@ -0,0 +1,133 @@ +/* + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package compiler.compilercontrol.share.processors; + +import compiler.compilercontrol.share.method.MethodDescriptor; +import compiler.compilercontrol.share.method.MethodGenerator; +import compiler.compilercontrol.share.scenario.State; +import jdk.test.lib.Asserts; +import jdk.test.lib.OutputAnalyzer; +import jdk.test.lib.Pair; +import pool.PoolHelper; + +import java.io.File; +import java.io.FileNotFoundException; +import java.lang.reflect.Executable; +import java.util.List; +import java.util.Map; +import java.util.Scanner; +import java.util.function.Consumer; +import java.util.regex.Matcher; +import java.util.regex.Pattern; +import java.util.stream.Collectors; + +/** + * Log compilation file processor + */ +public class LogProcessor implements Consumer { + public static final String LOG_FILE = "compilation.log"; + private static final String TASK_ELEMENT = "]*>"; + private static final String TASK_DONE_ELEMENT = "]*>"; + private static final String TASK_END_ELEMENT = ""; + private static final String ANY_ELEMENT = "<[^>]*>"; + private static final Pattern METHOD_PATTERN = Pattern.compile( + "method='([^']+)'"); + private final List loggedMethods; + private final List testMethods; + private Scanner scanner = null; + + public LogProcessor(Map states) { + loggedMethods = states.keySet().stream() + .filter(x -> states.get(x).isLog()) + .map(MethodGenerator::logDescriptor) + .map(MethodDescriptor::getString) + .collect(Collectors.toList()); + testMethods = new PoolHelper().getAllMethods() + .stream() + .map(pair -> pair.first) + .map(MethodGenerator::logDescriptor) + .map(MethodDescriptor::getString) + .collect(Collectors.toList()); + } + + @Override + public void accept(OutputAnalyzer outputAnalyzer) { + if (loggedMethods.isEmpty()) { + return; + } + getScanner(); + matchTasks(); + } + + /* + * Gets scanner for log file of the test case + */ + private Scanner getScanner() { + File logFile = new File(LOG_FILE); + try { + scanner = new Scanner(logFile); + } catch (FileNotFoundException e) { + throw new Error("TESTBUG: file not found: " + logFile, e); + } + return scanner; + } + + /* + * Parses for <task method='java.lang.String indexOf (I)I' > + * and finds if there is a compilation log for this task + */ + private void matchTasks() { + String task = scanner.findWithinHorizon(TASK_ELEMENT, 0); + while (task != null) { + String element = scanner.findWithinHorizon(ANY_ELEMENT, 0); + if (Pattern.matches(TASK_DONE_ELEMENT, element) + || Pattern.matches(TASK_END_ELEMENT, element)) { + /* If there is nothing between and + except then compilation log is empty */ + Asserts.assertTrue(matchMethod(task), "Compilation log " + + "expected. Met: " + element); + } + task = scanner.findWithinHorizon(TASK_ELEMENT, 0); + } + } + + // Matches given string to regular expression + private boolean matchMethod(String input) { + Matcher matcher = METHOD_PATTERN.matcher(input); + Asserts.assertTrue(matcher.find(), "Wrong matcher or input"); + // Get method and normalize it + String method = normalize(matcher.group(1)); + // Check that this method matches regexp + return loggedMethods.contains(method) || !testMethods.contains(method); + } + + // Normalize given signature to conform regular expression used in tests + private String normalize(String method) { + return method.replaceAll("\\.", "/") // replace dots in a class string + .replaceFirst(" ", ".") // replace space between class and method + .replaceFirst(" ", "") // remove space between method and signature + .replace("<", "<") + .replace(">", ">"); + } +} diff --git a/test/compiler/compilercontrol/share/processors/PrintProcessor.java b/test/compiler/compilercontrol/share/processors/PrintProcessor.java new file mode 100644 --- /dev/null +++ b/test/compiler/compilercontrol/share/processors/PrintProcessor.java @@ -0,0 +1,115 @@ +/* + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package compiler.compilercontrol.share.processors; + +import com.sun.management.HotSpotDiagnosticMXBean; +import compiler.compilercontrol.share.method.MethodDescriptor; +import compiler.compilercontrol.share.method.MethodGenerator; +import compiler.compilercontrol.share.scenario.State; +import jdk.test.lib.OutputAnalyzer; +import jdk.test.lib.Pair; +import pool.PoolHelper; + +import java.lang.management.ManagementFactory; +import java.lang.reflect.Executable; +import java.util.List; +import java.util.Map; +import java.util.function.Consumer; +import java.util.regex.Matcher; +import java.util.regex.Pattern; +import java.util.stream.Collectors; + +/** + * Process output to find compiled methods assemblies printed by print command + */ +public class PrintProcessor implements Consumer { + /** + * Compiled method string pattern. + * Capturing groups are + * 1. Compiler used to compile this method + * 2. Time stamp + * 3. Compile ID + * 4. Method attributes + * 5. Compilation level + * 6. Method name + */ + private static final Pattern COMPILED_METHOD + = Pattern.compile("Compiled method (?\\(.*\\))[ ]+" + + "(?