2
* Copyright (c) 2016, 2024, Oracle and/or its affiliates. All rights reserved.
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5
* This code is free software; you can redistribute it and/or modify it
6
* under the terms of the GNU General Public License version 2 only, as
7
* published by the Free Software Foundation.
9
* This code is distributed in the hope that it will be useful, but WITHOUT
10
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12
* version 2 for more details (a copy is included in the LICENSE file that
13
* accompanied this code).
15
* You should have received a copy of the GNU General Public License version
16
* 2 along with this work; if not, write to the Free Software Foundation,
17
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
19
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20
* or visit www.oracle.com if you need additional information or have any
24
#include "precompiled.hpp"
25
#include "compiler/directivesParser.hpp"
26
#include "runtime/interfaceSupport.inline.hpp"
27
#include "runtime/thread.hpp"
28
#include "unittest.hpp"
32
class DirectivesParserTest : public ::testing::Test{
37
// These tests require the "C" locale to correctly parse decimal values
38
DirectivesParserTest() : _locale(os::strdup(setlocale(LC_NUMERIC, nullptr), mtTest)) {
39
setlocale(LC_NUMERIC, "C");
41
~DirectivesParserTest() {
42
setlocale(LC_NUMERIC, _locale);
46
void test_negative(const char* text) {
47
JavaThread* THREAD = JavaThread::current();
48
ThreadInVMfromNative ThreadInVMfromNative(THREAD);
49
DirectivesParser cd(text, &stream, false);
51
EXPECT_FALSE(cd.valid()) << "text: " << std::endl << text << std::endl << stream.as_string();
54
void test_positive(const char* text) {
55
JavaThread* THREAD = JavaThread::current();
56
ThreadInVMfromNative ThreadInVMfromNative(THREAD);
57
DirectivesParser cd(text, &stream, false);
59
EXPECT_TRUE(cd.valid()) << "text: " << std::endl << text << std::endl << stream.as_string();
63
TEST_VM_F(DirectivesParserTest, empty_object) {
67
TEST_VM_F(DirectivesParserTest, empty_array) {
71
TEST_VM_F(DirectivesParserTest, empty_object_in_array) {
72
test_negative("[{}]");
75
TEST_VM_F(DirectivesParserTest, empty_objects_in_array) {
76
test_negative("[{},{}]");
79
TEST_VM_F(DirectivesParserTest, empty_objects) {
80
test_negative("{},{}");
83
TEST_VM_F(DirectivesParserTest, simple_match) {
87
" match: \"foo/bar.*\"," "\n"
88
" inline : \"+java/util.*\"," "\n"
89
" PrintAssembly: true," "\n"
90
" BreakAtExecute: true," "\n"
96
TEST_VM_F(DirectivesParserTest, control_intrinsic) {
100
" match: \"foo/bar.*\"," "\n"
102
" DisableIntrinsic: \"_compareToL\"," "\n"
103
" ControlIntrinsic: \"+_mulAdd,+_getInt,-_arraycopy,+_compareToL\"" "\n"
110
TEST_VM_F(DirectivesParserTest, nesting_arrays) {
115
" match: \"foo/bar.*\"," "\n"
116
" inline : \"+java/util.*\"," "\n"
117
" PrintAssembly: true," "\n"
118
" BreakAtExecute: true," "\n"
124
TEST_VM_F(DirectivesParserTest, c1_block) {
128
" match: \"foo/bar.*\"," "\n"
130
" PrintInlining: false," "\n"
136
TEST_VM_F(DirectivesParserTest, c2_block) {
140
" match: \"foo/bar.*\"," "\n"
142
" PrintInlining: false," "\n"
148
TEST_VM_F(DirectivesParserTest, boolean_array) {
152
" match: \"foo/bar.*\"," "\n"
153
" PrintInlining: [" "\n"
161
TEST_VM_F(DirectivesParserTest, multiple_objects) {
165
" // pattern to match against class+method+signature" "\n"
166
" // leading and trailing wildcard (*) allowed" "\n"
167
" match: \"foo/bar.*\"," "\n"
169
" // override defaults for specified compiler" "\n"
170
" // we may differentiate between levels too. TBD." "\n"
172
" //override c1 presets " "\n"
173
" DumpReplay: false," "\n"
174
" BreakAtCompile: true," "\n"
178
" // control inlining of method" "\n"
179
" // + force inline, - dont inline" "\n"
180
" inline : \"+java/util.*\"," "\n"
181
" PrintInlining: true," "\n"
184
" // directives outside a specific preset applies to all compilers" "\n"
185
" inline : [ \"+java/util.*\", \"-com/sun.*\"]," "\n"
186
" BreakAtExecute: true," "\n"
190
" // matching several patterns require an array" "\n"
191
" match: [\"baz.*\",\"frob.*\"]," "\n"
193
" // applies to all compilers" "\n"
194
" // + force inline, - dont inline" "\n"
195
" inline : [ \"+java/util.*\", \"-com/sun.*\" ]," "\n"
196
" PrintInlining: true," "\n"
198
" // force matching compiles to be blocking/syncronous" "\n"
199
" PrintNMethods: true" "\n"
204
// Test max stack depth
205
TEST_VM_F(DirectivesParserTest, correct_max_stack_depth) {
207
"[" "\n" // depth 1: type_dir_array
208
" {" "\n" // depth 2: type_directives
209
" match: \"*.*\"," // match required
210
" c1:" "\n" // depth 3: type_c1
212
" inline:" "\n" // depth 4: type_inline
213
" [" "\n" // depth 5: type_value_array
216
" ]" "\n" // depth 3: pop type_value_array and type_inline keys
217
" }" "\n" // depth 2: pop type_c1 key
218
" }" "\n" // depth 1: pop type_directives key
219
"]" "\n"); // depth 0: pop type_dir_array key
222
// Test max stack depth
223
TEST_VM_F(DirectivesParserTest, incorrect_max_stack_depth) {
224
test_negative("[{c1:{c1:{c1:{c1:{c1:{c1:{c1:{}}}}}}}}]");