jdk

Форк
0
/
test_directivesParser.cpp 
225 строк · 6.8 Кб
1
/*
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.
4
 *
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.
8
 *
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).
14
 *
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.
18
 *
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
21
 * questions.
22
 */
23

24
#include "precompiled.hpp"
25
#include "compiler/directivesParser.hpp"
26
#include "runtime/interfaceSupport.inline.hpp"
27
#include "runtime/thread.hpp"
28
#include "unittest.hpp"
29

30
#include <locale.h>
31

32
class DirectivesParserTest : public ::testing::Test{
33
 protected:
34
  char* const _locale;
35
  ResourceMark rm;
36
  stringStream stream;
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");
40
  }
41
  ~DirectivesParserTest() {
42
    setlocale(LC_NUMERIC, _locale);
43
    os::free(_locale);
44
  }
45

46
  void test_negative(const char* text) {
47
    JavaThread* THREAD = JavaThread::current();
48
    ThreadInVMfromNative ThreadInVMfromNative(THREAD);
49
    DirectivesParser cd(text, &stream, false);
50
    cd.clean_tmp();
51
    EXPECT_FALSE(cd.valid()) << "text: " << std::endl << text << std::endl << stream.as_string();
52
  }
53

54
  void test_positive(const char* text) {
55
    JavaThread* THREAD = JavaThread::current();
56
    ThreadInVMfromNative ThreadInVMfromNative(THREAD);
57
    DirectivesParser cd(text, &stream, false);
58
    cd.clean_tmp();
59
    EXPECT_TRUE(cd.valid()) << "text: " << std::endl << text << std::endl << stream.as_string();
60
  }
61
};
62

63
TEST_VM_F(DirectivesParserTest, empty_object) {
64
  test_negative("{}");
65
}
66

67
TEST_VM_F(DirectivesParserTest, empty_array) {
68
  test_positive("[]");
69
}
70

71
TEST_VM_F(DirectivesParserTest, empty_object_in_array) {
72
  test_negative("[{}]");
73
}
74

75
TEST_VM_F(DirectivesParserTest, empty_objects_in_array) {
76
  test_negative("[{},{}]");
77
}
78

79
TEST_VM_F(DirectivesParserTest, empty_objects) {
80
  test_negative("{},{}");
81
}
82

83
TEST_VM_F(DirectivesParserTest, simple_match) {
84
  test_positive(
85
      "[" "\n"
86
      "  {" "\n"
87
      "    match: \"foo/bar.*\"," "\n"
88
      "    inline : \"+java/util.*\"," "\n"
89
      "    PrintAssembly: true," "\n"
90
      "    BreakAtExecute: true," "\n"
91
      "  }" "\n"
92
      "]" "\n");
93

94
}
95

96
TEST_VM_F(DirectivesParserTest, control_intrinsic) {
97
  test_positive(
98
      "[" "\n"
99
      "  {" "\n"
100
      "    match: \"foo/bar.*\"," "\n"
101
      "    c2: {" "\n"
102
      "      DisableIntrinsic: \"_compareToL\"," "\n"
103
      "      ControlIntrinsic: \"+_mulAdd,+_getInt,-_arraycopy,+_compareToL\"" "\n"
104
      "    }" "\n"
105
      "  }" "\n"
106
      "]" "\n");
107

108
}
109

110
TEST_VM_F(DirectivesParserTest, nesting_arrays) {
111
  test_negative(
112
      "[" "\n"
113
      "  [" "\n"
114
      "    {" "\n"
115
      "      match: \"foo/bar.*\"," "\n"
116
      "      inline : \"+java/util.*\"," "\n"
117
      "      PrintAssembly: true," "\n"
118
      "      BreakAtExecute: true," "\n"
119
      "    }" "\n"
120
      "  ]" "\n"
121
      "]" "\n");
122
}
123

124
TEST_VM_F(DirectivesParserTest, c1_block) {
125
  test_positive(
126
    "[" "\n"
127
    "  {" "\n"
128
    "    match: \"foo/bar.*\"," "\n"
129
    "    c1: {"
130
    "      PrintInlining: false," "\n"
131
    "    }" "\n"
132
    "  }" "\n"
133
    "]" "\n");
134
}
135

136
TEST_VM_F(DirectivesParserTest, c2_block) {
137
  test_positive(
138
      "[" "\n"
139
      "  {" "\n"
140
      "    match: \"foo/bar.*\"," "\n"
141
      "    c2: {" "\n"
142
      "      PrintInlining: false," "\n"
143
      "    }" "\n"
144
      "  }" "\n"
145
      "]" "\n");
146
}
147

148
TEST_VM_F(DirectivesParserTest, boolean_array) {
149
  test_negative(
150
      "[" "\n"
151
      "  {" "\n"
152
      "    match: \"foo/bar.*\"," "\n"
153
      "    PrintInlining: [" "\n"
154
      "      true," "\n"
155
      "      false" "\n"
156
      "    ]," "\n"
157
      "  }" "\n"
158
      "]" "\n");
159
}
160

161
TEST_VM_F(DirectivesParserTest, multiple_objects) {
162
  test_positive(
163
      "[" "\n"
164
      "  {"
165
      "    // pattern to match against class+method+signature" "\n"
166
      "    // leading and trailing wildcard (*) allowed" "\n"
167
      "    match: \"foo/bar.*\"," "\n"
168
      "" "\n"
169
      "    // override defaults for specified compiler" "\n"
170
      "    // we may differentiate between levels too. TBD." "\n"
171
      "    c1:  {" "\n"
172
      "      //override c1 presets " "\n"
173
      "      DumpReplay: false," "\n"
174
      "      BreakAtCompile: true," "\n"
175
      "    }," "\n"
176
      "" "\n"
177
      "    c2: {" "\n"
178
      "        // control inlining of method" "\n"
179
      "        // + force inline, - dont inline" "\n"
180
      "        inline : \"+java/util.*\"," "\n"
181
      "        PrintInlining: true," "\n"
182
      "    }," "\n"
183
      "" "\n"
184
      "    // directives outside a specific preset applies to all compilers" "\n"
185
      "    inline : [ \"+java/util.*\", \"-com/sun.*\"]," "\n"
186
      "    BreakAtExecute: true," "\n"
187
      "    Log: true," "\n"
188
      "  }," "\n"
189
      "  {" "\n"
190
      "    // matching several patterns require an array" "\n"
191
      "    match: [\"baz.*\",\"frob.*\"]," "\n"
192
      "" "\n"
193
      "    // applies to all compilers" "\n"
194
      "    // + force inline, - dont inline" "\n"
195
      "    inline : [ \"+java/util.*\", \"-com/sun.*\" ]," "\n"
196
      "    PrintInlining: true," "\n"
197
      "" "\n"
198
      "    // force matching compiles to be blocking/syncronous" "\n"
199
      "    PrintNMethods: true" "\n"
200
      "  }," "\n"
201
      "]" "\n");
202
}
203

204
// Test max stack depth
205
TEST_VM_F(DirectivesParserTest, correct_max_stack_depth) {
206
  test_positive(
207
      "[" "\n"              // depth 1: type_dir_array
208
      "  {" "\n"            // depth 2: type_directives
209
      "    match: \"*.*\"," // match required
210
      "    c1:" "\n"        // depth 3: type_c1
211
      "    {" "\n"
212
      "      inline:" "\n"  // depth 4: type_inline
213
      "      [" "\n"        // depth 5: type_value_array
214
      "        \"foo\"," "\n"
215
      "        \"bar\"," "\n"
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
220
}
221

222
// Test max stack depth
223
TEST_VM_F(DirectivesParserTest, incorrect_max_stack_depth) {
224
  test_negative("[{c1:{c1:{c1:{c1:{c1:{c1:{c1:{}}}}}}}}]");
225
}
226

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.