1/*
2 * Copyright (c) 2015, 2019, 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
25#ifndef SHARE_COMPILER_METHODMATCHER_HPP
26#define SHARE_COMPILER_METHODMATCHER_HPP
27
28#include "memory/allocation.hpp"
29#include "runtime/handles.hpp"
30#include "memory/resourceArea.hpp"
31
32class MethodMatcher : public CHeapObj<mtCompiler> {
33 public:
34 enum Mode {
35 Exact,
36 Prefix = 1,
37 Suffix = 2,
38 Substring = Prefix | Suffix,
39 Any,
40 Unknown = -1
41 };
42
43 protected:
44 Symbol* _class_name;
45 Symbol* _method_name;
46 Symbol* _signature;
47 Mode _class_mode;
48 Mode _method_mode;
49
50 public:
51 Symbol* class_name() const { return _class_name; }
52 Mode class_mode() const { return _class_mode; }
53 Symbol* method_name() const { return _method_name; }
54 Mode method_mode() const { return _method_mode; }
55 Symbol* signature() const { return _signature; }
56
57 MethodMatcher();
58 ~MethodMatcher();
59
60 void init(Symbol* class_name, Mode class_mode, Symbol* method_name, Mode method_mode, Symbol* signature);
61 static void parse_method_pattern(char*& line, const char*& error_msg, MethodMatcher* m);
62 static void print_symbol(outputStream* st, Symbol* h, Mode mode);
63 bool matches(const methodHandle& method) const;
64 void print_base(outputStream* st);
65
66 private:
67 static bool canonicalize(char * line, const char *& error_msg);
68 bool match(Symbol* candidate, Symbol* match, Mode match_mode) const;
69};
70
71class BasicMatcher : public MethodMatcher {
72private:
73 BasicMatcher* _next;
74public:
75
76 BasicMatcher() : MethodMatcher(),
77 _next(NULL) {
78 }
79
80 BasicMatcher(BasicMatcher* next) :
81 _next(next) {
82 }
83
84 static BasicMatcher* parse_method_pattern(char* line, const char*& error_msg);
85 bool match(const methodHandle& method);
86 void set_next(BasicMatcher* next) { _next = next; }
87 BasicMatcher* next() { return _next; }
88
89 void print(outputStream* st) { print_base(st); }
90 void print_all(outputStream* st) {
91 print_base(st);
92 if (_next != NULL) {
93 _next->print_all(st);
94 }
95 }
96};
97
98class InlineMatcher : public MethodMatcher {
99public:
100 enum InlineType {
101 unknown_inline,
102 dont_inline,
103 force_inline
104 };
105
106private:
107 InlineType _inline_action;
108 InlineMatcher * _next;
109
110 InlineMatcher() : MethodMatcher(),
111 _inline_action(unknown_inline), _next(NULL) {
112 }
113
114public:
115 static InlineMatcher* parse_method_pattern(char* line, const char*& error_msg);
116 bool match(const methodHandle& method, int inline_action);
117 void print(outputStream* st);
118 void set_next(InlineMatcher* next) { _next = next; }
119 InlineMatcher* next() { return _next; }
120 void set_action(InlineType inline_action) { _inline_action = inline_action; }
121 int inline_action() { return _inline_action; }
122 static InlineMatcher* parse_inline_pattern(char* line, const char*& error_msg);
123 InlineMatcher* clone();
124};
125
126#endif // SHARE_COMPILER_METHODMATCHER_HPP
127