# HG changeset patch # User neliasso # Date 1421921114 -3600 # Node ID 76473974643b3f6425317e7da723526f17bbc75c # Parent 5a9aedf87213393099caf0c5f83a8eb75e9f98b6 8069389: CompilerOracle prefix wildcarding is broken for long strings Summary: Replace strcpy with memmove Reviewed-by: kvn diff -r 5a9aedf87213 -r 76473974643b hotspot/src/share/vm/compiler/compilerOracle.cpp --- a/hotspot/src/share/vm/compiler/compilerOracle.cpp Thu Jan 22 09:07:41 2015 +0100 +++ b/hotspot/src/share/vm/compiler/compilerOracle.cpp Thu Jan 22 11:05:14 2015 +0100 @@ -553,7 +553,8 @@ int match = MethodMatcher::Exact; while (name[0] == '*') { match |= MethodMatcher::Suffix; - strcpy(name, name + 1); + // Copy remaining string plus NUL to the beginning + memmove(name, name + 1, strlen(name + 1) + 1); } if (strcmp(name, "*") == 0) return MethodMatcher::Any; diff -r 5a9aedf87213 -r 76473974643b hotspot/test/compiler/oracle/TestCompileCommand.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/hotspot/test/compiler/oracle/TestCompileCommand.java Thu Jan 22 11:05:14 2015 +0100 @@ -0,0 +1,78 @@ +/* + * 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. + */ + +import java.io.PrintWriter; +import java.io.File; + +import com.oracle.java.testlibrary.*; + +/* + * @test TestCompileCommand + * @bug 8069389 + * @summary "Regression tests of -XX:CompileCommand" + * @library /testlibrary + * @run main TestCompileCommand + */ + +public class TestCompileCommand { + + private static final String[][] ARGUMENTS = { + { + "-XX:CompileCommand=print,*01234567890123456789012345678901234567890123456789,*0123456789012345678901234567890123456789", + "-version" + } + }; + + private static final String[][] OUTPUTS = { + { + "print *01234567890123456789012345678901234567890123456789.*0123456789012345678901234567890123456789" + } + }; + + private static void verifyValidOption(String[] arguments, String[] expected_outputs) throws Exception { + ProcessBuilder pb; + OutputAnalyzer out; + + pb = ProcessTools.createJavaProcessBuilder(arguments); + out = new OutputAnalyzer(pb.start()); + + for (String expected_output : expected_outputs) { + out.shouldContain(expected_output); + } + + out.shouldNotContain("CompileCommand: An error occured during parsing"); + out.shouldHaveExitValue(0); + } + + public static void main(String[] args) throws Exception { + + if (ARGUMENTS.length != OUTPUTS.length) { + throw new RuntimeException("Test is set up incorrectly: length of arguments and expected outputs for type (1) options does not match."); + } + + // Check if type (1) options are parsed correctly + for (int i = 0; i < ARGUMENTS.length; i++) { + verifyValidOption(ARGUMENTS[i], OUTPUTS[i]); + } + } +}