methodMatcher.hpp revision 9248:6ab7e19c9220
1/*
2 * Copyright (c) 2015, 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_VM_COMPILER_METHODMATCHER_HPP
26#define SHARE_VM_COMPILER_METHODMATCHER_HPP
27
28#include "memory/allocation.inline.hpp"
29#include "runtime/handles.inline.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    assert(error_msg == NULL, "Dont call here with error_msg already set");
86    BasicMatcher* bm = new BasicMatcher();
87    MethodMatcher::parse_method_pattern(line, error_msg, bm);
88    if (error_msg != NULL) {
89      delete bm;
90      return NULL;
91    }
92
93    // check for bad trailing characters
94    int bytes_read = 0;
95    sscanf(line, "%*[ \t]%n", &bytes_read);
96    if (line[bytes_read] != '\0') {
97      error_msg = "Unrecognized trailing text after method pattern";
98      delete bm;
99      return NULL;
100    }
101    return bm;
102  }
103
104  bool match(const methodHandle& method) {
105    for (BasicMatcher* current = this; current != NULL; current = current->next()) {
106      if (current->matches(method)) {
107        return true;
108      }
109    }
110    return false;
111  }
112
113  void set_next(BasicMatcher* next) { _next = next; }
114  BasicMatcher* next() { return _next; }
115
116  void print(outputStream* st) { print_base(st); }
117  void print_all(outputStream* st) {
118    print_base(st);
119    if (_next != NULL) {
120      _next->print_all(st);
121    }
122  }
123};
124
125#endif // SHARE_VM_COMPILER_METHODMATCHER_HPP
126
127