Path: blob/master/test/hotspot/gtest/compiler/test_directivesParser.cpp
41145 views
/*1* Copyright (c) 2016, 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#include "precompiled.hpp"2425#include <locale.h>2627#include "compiler/directivesParser.hpp"28#include "runtime/interfaceSupport.inline.hpp"29#include "runtime/thread.hpp"30#include "unittest.hpp"3132class DirectivesParserTest : public ::testing::Test{33protected:34const char* const _locale;35ResourceMark rm;36stringStream stream;37// These tests require the "C" locale to correctly parse decimal values38DirectivesParserTest() : _locale(setlocale(LC_NUMERIC, NULL)) {39setlocale(LC_NUMERIC, "C");40}41~DirectivesParserTest() {42setlocale(LC_NUMERIC, _locale);43}4445void test_negative(const char* text) {46JavaThread* THREAD = JavaThread::current();47ThreadInVMfromNative ThreadInVMfromNative(THREAD);48DirectivesParser cd(text, &stream, false);49cd.clean_tmp();50EXPECT_FALSE(cd.valid()) << "text: " << std::endl << text << std::endl << stream.as_string();51}5253void test_positive(const char* text) {54JavaThread* THREAD = JavaThread::current();55ThreadInVMfromNative ThreadInVMfromNative(THREAD);56DirectivesParser cd(text, &stream, false);57cd.clean_tmp();58EXPECT_TRUE(cd.valid()) << "text: " << std::endl << text << std::endl << stream.as_string();59}60};6162TEST_VM_F(DirectivesParserTest, empty_object) {63test_negative("{}");64}6566TEST_VM_F(DirectivesParserTest, empty_array) {67test_positive("[]");68}6970TEST_VM_F(DirectivesParserTest, empty_object_in_array) {71test_negative("[{}]");72}7374TEST_VM_F(DirectivesParserTest, empty_objects_in_array) {75test_negative("[{},{}]");76}7778TEST_VM_F(DirectivesParserTest, empty_objects) {79test_negative("{},{}");80}8182TEST_VM_F(DirectivesParserTest, simple_match) {83test_positive(84"[" "\n"85" {" "\n"86" match: \"foo/bar.*\"," "\n"87" inline : \"+java/util.*\"," "\n"88" PrintAssembly: true," "\n"89" BreakAtExecute: true," "\n"90" }" "\n"91"]" "\n");9293}9495TEST_VM_F(DirectivesParserTest, control_intrinsic) {96test_positive(97"[" "\n"98" {" "\n"99" match: \"foo/bar.*\"," "\n"100" c2: {" "\n"101" DisableIntrinsic: \"_compareToL\"," "\n"102" ControlIntrinsic: \"+_mulAdd,+_getInt,-_arraycopy,+_compareToL\"" "\n"103" }" "\n"104" }" "\n"105"]" "\n");106107}108109TEST_VM_F(DirectivesParserTest, nesting_arrays) {110test_negative(111"[" "\n"112" [" "\n"113" {" "\n"114" match: \"foo/bar.*\"," "\n"115" inline : \"+java/util.*\"," "\n"116" PrintAssembly: true," "\n"117" BreakAtExecute: true," "\n"118" }" "\n"119" ]" "\n"120"]" "\n");121}122123TEST_VM_F(DirectivesParserTest, c1_block) {124test_positive(125"[" "\n"126" {" "\n"127" match: \"foo/bar.*\"," "\n"128" c1: {"129" PrintInlining: false," "\n"130" }" "\n"131" }" "\n"132"]" "\n");133}134135TEST_VM_F(DirectivesParserTest, c2_block) {136test_positive(137"[" "\n"138" {" "\n"139" match: \"foo/bar.*\"," "\n"140" c2: {" "\n"141" PrintInlining: false," "\n"142" }" "\n"143" }" "\n"144"]" "\n");145}146147TEST_VM_F(DirectivesParserTest, boolean_array) {148test_negative(149"[" "\n"150" {" "\n"151" match: \"foo/bar.*\"," "\n"152" PrintInlining: [" "\n"153" true," "\n"154" false" "\n"155" ]," "\n"156" }" "\n"157"]" "\n");158}159160TEST_VM_F(DirectivesParserTest, multiple_objects) {161test_positive(162"[" "\n"163" {"164" // pattern to match against class+method+signature" "\n"165" // leading and trailing wildcard (*) allowed" "\n"166" match: \"foo/bar.*\"," "\n"167"" "\n"168" // override defaults for specified compiler" "\n"169" // we may differentiate between levels too. TBD." "\n"170" c1: {" "\n"171" //override c1 presets " "\n"172" DumpReplay: false," "\n"173" BreakAtCompile: true," "\n"174" }," "\n"175"" "\n"176" c2: {" "\n"177" // control inlining of method" "\n"178" // + force inline, - dont inline" "\n"179" inline : \"+java/util.*\"," "\n"180" PrintInlining: true," "\n"181" }," "\n"182"" "\n"183" // directives outside a specific preset applies to all compilers" "\n"184" inline : [ \"+java/util.*\", \"-com/sun.*\"]," "\n"185" BreakAtExecute: true," "\n"186" Log: true," "\n"187" }," "\n"188" {" "\n"189" // matching several patterns require an array" "\n"190" match: [\"baz.*\",\"frob.*\"]," "\n"191"" "\n"192" // applies to all compilers" "\n"193" // + force inline, - dont inline" "\n"194" inline : [ \"+java/util.*\", \"-com/sun.*\" ]," "\n"195" PrintInlining: true," "\n"196"" "\n"197" // force matching compiles to be blocking/syncronous" "\n"198" PrintNMethods: true" "\n"199" }," "\n"200"]" "\n");201}202203// Test max stack depth204TEST_VM_F(DirectivesParserTest, correct_max_stack_depth) {205test_positive(206"[" "\n" // depth 1: type_dir_array207" {" "\n" // depth 2: type_directives208" match: \"*.*\"," // match required209" c1:" "\n" // depth 3: type_c1210" {" "\n"211" inline:" "\n" // depth 4: type_inline212" [" "\n" // depth 5: type_value_array213" \"foo\"," "\n"214" \"bar\"," "\n"215" ]" "\n" // depth 3: pop type_value_array and type_inline keys216" }" "\n" // depth 2: pop type_c1 key217" }" "\n" // depth 1: pop type_directives key218"]" "\n"); // depth 0: pop type_dir_array key219}220221// Test max stack depth222TEST_VM_F(DirectivesParserTest, incorrect_max_stack_depth) {223test_negative("[{c1:{c1:{c1:{c1:{c1:{c1:{c1:{}}}}}}}}]");224}225226227