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