annotate graal/com.oracle.jvmci.debug/src/com/oracle/jvmci/debug/MethodFilter.java @ 21780:3d15183f3c93

Introduce Compiler interface in jvmci. Use it from jvmci.hotspot.CompilationTask
author Gilles Duboscq <gilles.m.duboscq@oracle.com>
date Wed, 03 Jun 2015 15:47:54 +0200
parents graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/MethodFilter.java@f5b549811bac
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
7318
323ece2b012b Refactor debug environment creation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
1 /*
323ece2b012b Refactor debug environment creation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
2 * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
323ece2b012b Refactor debug environment creation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
323ece2b012b Refactor debug environment creation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
4 *
323ece2b012b Refactor debug environment creation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
323ece2b012b Refactor debug environment creation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
323ece2b012b Refactor debug environment creation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
7 * published by the Free Software Foundation.
323ece2b012b Refactor debug environment creation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
8 *
323ece2b012b Refactor debug environment creation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
323ece2b012b Refactor debug environment creation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
323ece2b012b Refactor debug environment creation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
323ece2b012b Refactor debug environment creation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
323ece2b012b Refactor debug environment creation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
13 * accompanied this code).
323ece2b012b Refactor debug environment creation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
14 *
323ece2b012b Refactor debug environment creation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
323ece2b012b Refactor debug environment creation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
323ece2b012b Refactor debug environment creation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
323ece2b012b Refactor debug environment creation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
18 *
323ece2b012b Refactor debug environment creation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
323ece2b012b Refactor debug environment creation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
20 * or visit www.oracle.com if you need additional information or have any
323ece2b012b Refactor debug environment creation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
21 * questions.
323ece2b012b Refactor debug environment creation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
22 */
21780
3d15183f3c93 Introduce Compiler interface in jvmci. Use it from jvmci.hotspot.CompilationTask
Gilles Duboscq <gilles.m.duboscq@oracle.com>
parents: 21565
diff changeset
23 package com.oracle.jvmci.debug;
7318
323ece2b012b Refactor debug environment creation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
24
21556
48c1ebd24120 renamed com.oracle.graal.api[meta|code] modules to com.oracle.jvmci.[meta|code] (JBS:GRAAL-53)
Doug Simon <doug.simon@oracle.com>
parents: 20046
diff changeset
25 import com.oracle.jvmci.meta.JavaType;
48c1ebd24120 renamed com.oracle.graal.api[meta|code] modules to com.oracle.jvmci.[meta|code] (JBS:GRAAL-53)
Doug Simon <doug.simon@oracle.com>
parents: 20046
diff changeset
26 import com.oracle.jvmci.meta.JavaMethod;
48c1ebd24120 renamed com.oracle.graal.api[meta|code] modules to com.oracle.jvmci.[meta|code] (JBS:GRAAL-53)
Doug Simon <doug.simon@oracle.com>
parents: 20046
diff changeset
27 import com.oracle.jvmci.meta.Signature;
7318
323ece2b012b Refactor debug environment creation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
28 import java.util.*;
323ece2b012b Refactor debug environment creation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
29 import java.util.regex.*;
323ece2b012b Refactor debug environment creation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
30
323ece2b012b Refactor debug environment creation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
31 /**
7530
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7318
diff changeset
32 * This class implements a method filter that can filter based on class name, method name and
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7318
diff changeset
33 * parameters. The syntax for the source pattern that is passed to the constructor is as follows:
14906
f3a5036cc13c javadoc fixes
Bernhard Urban <bernhard.urban@jku.at>
parents: 13090
diff changeset
34 *
7318
323ece2b012b Refactor debug environment creation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
35 * <pre>
13090
4fcc7d778e0f MethodFilter: add documentation about comma seperator
Bernhard Urban <bernhard.urban@jku.at>
parents: 11491
diff changeset
36 * SourcePatterns = SourcePattern ["," SourcePatterns] .
7318
323ece2b012b Refactor debug environment creation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
37 * SourcePattern = [ Class "." ] method [ "(" [ Parameter { ";" Parameter } ] ")" ] .
323ece2b012b Refactor debug environment creation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
38 * Parameter = Class | "int" | "long" | "float" | "double" | "short" | "char" | "boolean" .
323ece2b012b Refactor debug environment creation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
39 * Class = { package "." } class .
323ece2b012b Refactor debug environment creation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
40 * </pre>
14906
f3a5036cc13c javadoc fixes
Bernhard Urban <bernhard.urban@jku.at>
parents: 13090
diff changeset
41 *
f3a5036cc13c javadoc fixes
Bernhard Urban <bernhard.urban@jku.at>
parents: 13090
diff changeset
42 *
7530
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7318
diff changeset
43 * Glob pattern matching (*, ?) is allowed in all parts of the source pattern. Examples for valid
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7318
diff changeset
44 * filters are:
14906
f3a5036cc13c javadoc fixes
Bernhard Urban <bernhard.urban@jku.at>
parents: 13090
diff changeset
45 *
7318
323ece2b012b Refactor debug environment creation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
46 * <ul>
7530
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7318
diff changeset
47 * <li>
14906
f3a5036cc13c javadoc fixes
Bernhard Urban <bernhard.urban@jku.at>
parents: 13090
diff changeset
48 *
7530
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7318
diff changeset
49 * <pre>
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7318
diff changeset
50 * visit(Argument;BlockScope)
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7318
diff changeset
51 * </pre>
14906
f3a5036cc13c javadoc fixes
Bernhard Urban <bernhard.urban@jku.at>
parents: 13090
diff changeset
52 *
7530
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7318
diff changeset
53 * Matches all methods named "visit", with the first parameter of type "Argument", and the second
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7318
diff changeset
54 * parameter of type "BlockScope". The packages of the parameter types are irrelevant.</li>
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7318
diff changeset
55 * <li>
14906
f3a5036cc13c javadoc fixes
Bernhard Urban <bernhard.urban@jku.at>
parents: 13090
diff changeset
56 *
7530
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7318
diff changeset
57 * <pre>
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7318
diff changeset
58 * arraycopy(Object;;;;)
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7318
diff changeset
59 * </pre>
14906
f3a5036cc13c javadoc fixes
Bernhard Urban <bernhard.urban@jku.at>
parents: 13090
diff changeset
60 *
7530
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7318
diff changeset
61 * Matches all methods named "arraycopy", with the first parameter of type "Object", and four more
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7318
diff changeset
62 * parameters of any type. The packages of the parameter types are irrelevant.</li>
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7318
diff changeset
63 * <li>
14906
f3a5036cc13c javadoc fixes
Bernhard Urban <bernhard.urban@jku.at>
parents: 13090
diff changeset
64 *
7530
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7318
diff changeset
65 * <pre>
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7318
diff changeset
66 * com.oracle.graal.compiler.graph.PostOrderNodeIterator.*
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7318
diff changeset
67 * </pre>
14906
f3a5036cc13c javadoc fixes
Bernhard Urban <bernhard.urban@jku.at>
parents: 13090
diff changeset
68 *
7318
323ece2b012b Refactor debug environment creation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
69 * Matches all methods in the class "com.oracle.graal.compiler.graph.PostOrderNodeIterator".</li>
7530
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7318
diff changeset
70 * <li>
14906
f3a5036cc13c javadoc fixes
Bernhard Urban <bernhard.urban@jku.at>
parents: 13090
diff changeset
71 *
7530
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7318
diff changeset
72 * <pre>
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7318
diff changeset
73 * *
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7318
diff changeset
74 * </pre>
14906
f3a5036cc13c javadoc fixes
Bernhard Urban <bernhard.urban@jku.at>
parents: 13090
diff changeset
75 *
7318
323ece2b012b Refactor debug environment creation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
76 * Matches all methods in all classes</li>
7530
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7318
diff changeset
77 * <li>
14906
f3a5036cc13c javadoc fixes
Bernhard Urban <bernhard.urban@jku.at>
parents: 13090
diff changeset
78 *
7530
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7318
diff changeset
79 * <pre>
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7318
diff changeset
80 * com.oracle.graal.compiler.graph.*.visit
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7318
diff changeset
81 * </pre>
14906
f3a5036cc13c javadoc fixes
Bernhard Urban <bernhard.urban@jku.at>
parents: 13090
diff changeset
82 *
f3a5036cc13c javadoc fixes
Bernhard Urban <bernhard.urban@jku.at>
parents: 13090
diff changeset
83 * Matches all methods named "visit" in classes in the package "com.oracle.graal.compiler.graph".
13090
4fcc7d778e0f MethodFilter: add documentation about comma seperator
Bernhard Urban <bernhard.urban@jku.at>
parents: 11491
diff changeset
84 * <li>
14906
f3a5036cc13c javadoc fixes
Bernhard Urban <bernhard.urban@jku.at>
parents: 13090
diff changeset
85 *
13090
4fcc7d778e0f MethodFilter: add documentation about comma seperator
Bernhard Urban <bernhard.urban@jku.at>
parents: 11491
diff changeset
86 * <pre>
4fcc7d778e0f MethodFilter: add documentation about comma seperator
Bernhard Urban <bernhard.urban@jku.at>
parents: 11491
diff changeset
87 * arraycopy,toString
4fcc7d778e0f MethodFilter: add documentation about comma seperator
Bernhard Urban <bernhard.urban@jku.at>
parents: 11491
diff changeset
88 * </pre>
14906
f3a5036cc13c javadoc fixes
Bernhard Urban <bernhard.urban@jku.at>
parents: 13090
diff changeset
89 *
13090
4fcc7d778e0f MethodFilter: add documentation about comma seperator
Bernhard Urban <bernhard.urban@jku.at>
parents: 11491
diff changeset
90 * Matches all methods named "arraycopy" or "toString", meaning that ',' acts as an <i>or</i>
4fcc7d778e0f MethodFilter: add documentation about comma seperator
Bernhard Urban <bernhard.urban@jku.at>
parents: 11491
diff changeset
91 * operator.</li>
7318
323ece2b012b Refactor debug environment creation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
92 * </ul>
323ece2b012b Refactor debug environment creation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
93 */
323ece2b012b Refactor debug environment creation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
94 public class MethodFilter {
323ece2b012b Refactor debug environment creation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
95
323ece2b012b Refactor debug environment creation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
96 private final Pattern clazz;
323ece2b012b Refactor debug environment creation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
97 private final Pattern methodName;
323ece2b012b Refactor debug environment creation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
98 private final Pattern[] signature;
323ece2b012b Refactor debug environment creation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
99
11491
a03452edfc4d made enabling/disabling of intrinsifications extensible (GRAAL-111)
Doug Simon <doug.simon@oracle.com>
parents: 7530
diff changeset
100 /**
a03452edfc4d made enabling/disabling of intrinsifications extensible (GRAAL-111)
Doug Simon <doug.simon@oracle.com>
parents: 7530
diff changeset
101 * Parses a string containing list of comma separated filter patterns into an array of
a03452edfc4d made enabling/disabling of intrinsifications extensible (GRAAL-111)
Doug Simon <doug.simon@oracle.com>
parents: 7530
diff changeset
102 * {@link MethodFilter}s.
a03452edfc4d made enabling/disabling of intrinsifications extensible (GRAAL-111)
Doug Simon <doug.simon@oracle.com>
parents: 7530
diff changeset
103 */
a03452edfc4d made enabling/disabling of intrinsifications extensible (GRAAL-111)
Doug Simon <doug.simon@oracle.com>
parents: 7530
diff changeset
104 public static MethodFilter[] parse(String commaSeparatedPatterns) {
a03452edfc4d made enabling/disabling of intrinsifications extensible (GRAAL-111)
Doug Simon <doug.simon@oracle.com>
parents: 7530
diff changeset
105 String[] filters = commaSeparatedPatterns.split(",");
a03452edfc4d made enabling/disabling of intrinsifications extensible (GRAAL-111)
Doug Simon <doug.simon@oracle.com>
parents: 7530
diff changeset
106 MethodFilter[] methodFilters = new MethodFilter[filters.length];
a03452edfc4d made enabling/disabling of intrinsifications extensible (GRAAL-111)
Doug Simon <doug.simon@oracle.com>
parents: 7530
diff changeset
107 for (int i = 0; i < filters.length; i++) {
a03452edfc4d made enabling/disabling of intrinsifications extensible (GRAAL-111)
Doug Simon <doug.simon@oracle.com>
parents: 7530
diff changeset
108 methodFilters[i] = new MethodFilter(filters[i]);
a03452edfc4d made enabling/disabling of intrinsifications extensible (GRAAL-111)
Doug Simon <doug.simon@oracle.com>
parents: 7530
diff changeset
109 }
a03452edfc4d made enabling/disabling of intrinsifications extensible (GRAAL-111)
Doug Simon <doug.simon@oracle.com>
parents: 7530
diff changeset
110 return methodFilters;
a03452edfc4d made enabling/disabling of intrinsifications extensible (GRAAL-111)
Doug Simon <doug.simon@oracle.com>
parents: 7530
diff changeset
111 }
a03452edfc4d made enabling/disabling of intrinsifications extensible (GRAAL-111)
Doug Simon <doug.simon@oracle.com>
parents: 7530
diff changeset
112
a03452edfc4d made enabling/disabling of intrinsifications extensible (GRAAL-111)
Doug Simon <doug.simon@oracle.com>
parents: 7530
diff changeset
113 /**
a03452edfc4d made enabling/disabling of intrinsifications extensible (GRAAL-111)
Doug Simon <doug.simon@oracle.com>
parents: 7530
diff changeset
114 * Determines if a given method is matched by a given array of filters.
a03452edfc4d made enabling/disabling of intrinsifications extensible (GRAAL-111)
Doug Simon <doug.simon@oracle.com>
parents: 7530
diff changeset
115 */
a03452edfc4d made enabling/disabling of intrinsifications extensible (GRAAL-111)
Doug Simon <doug.simon@oracle.com>
parents: 7530
diff changeset
116 public static boolean matches(MethodFilter[] filters, JavaMethod method) {
a03452edfc4d made enabling/disabling of intrinsifications extensible (GRAAL-111)
Doug Simon <doug.simon@oracle.com>
parents: 7530
diff changeset
117 for (MethodFilter filter : filters) {
a03452edfc4d made enabling/disabling of intrinsifications extensible (GRAAL-111)
Doug Simon <doug.simon@oracle.com>
parents: 7530
diff changeset
118 if (filter.matches(method)) {
a03452edfc4d made enabling/disabling of intrinsifications extensible (GRAAL-111)
Doug Simon <doug.simon@oracle.com>
parents: 7530
diff changeset
119 return true;
a03452edfc4d made enabling/disabling of intrinsifications extensible (GRAAL-111)
Doug Simon <doug.simon@oracle.com>
parents: 7530
diff changeset
120 }
a03452edfc4d made enabling/disabling of intrinsifications extensible (GRAAL-111)
Doug Simon <doug.simon@oracle.com>
parents: 7530
diff changeset
121 }
a03452edfc4d made enabling/disabling of intrinsifications extensible (GRAAL-111)
Doug Simon <doug.simon@oracle.com>
parents: 7530
diff changeset
122 return false;
a03452edfc4d made enabling/disabling of intrinsifications extensible (GRAAL-111)
Doug Simon <doug.simon@oracle.com>
parents: 7530
diff changeset
123 }
a03452edfc4d made enabling/disabling of intrinsifications extensible (GRAAL-111)
Doug Simon <doug.simon@oracle.com>
parents: 7530
diff changeset
124
20018
3cbb0846337c added -G:CompileTheWorldMethodFilter option
Doug Simon <doug.simon@oracle.com>
parents: 18866
diff changeset
125 /**
3cbb0846337c added -G:CompileTheWorldMethodFilter option
Doug Simon <doug.simon@oracle.com>
parents: 18866
diff changeset
126 * Determines if a given class name is matched by a given array of filters.
3cbb0846337c added -G:CompileTheWorldMethodFilter option
Doug Simon <doug.simon@oracle.com>
parents: 18866
diff changeset
127 */
3cbb0846337c added -G:CompileTheWorldMethodFilter option
Doug Simon <doug.simon@oracle.com>
parents: 18866
diff changeset
128 public static boolean matchesClassName(MethodFilter[] filters, String className) {
3cbb0846337c added -G:CompileTheWorldMethodFilter option
Doug Simon <doug.simon@oracle.com>
parents: 18866
diff changeset
129 for (MethodFilter filter : filters) {
3cbb0846337c added -G:CompileTheWorldMethodFilter option
Doug Simon <doug.simon@oracle.com>
parents: 18866
diff changeset
130 if (filter.matchesClassName(className)) {
3cbb0846337c added -G:CompileTheWorldMethodFilter option
Doug Simon <doug.simon@oracle.com>
parents: 18866
diff changeset
131 return true;
3cbb0846337c added -G:CompileTheWorldMethodFilter option
Doug Simon <doug.simon@oracle.com>
parents: 18866
diff changeset
132 }
3cbb0846337c added -G:CompileTheWorldMethodFilter option
Doug Simon <doug.simon@oracle.com>
parents: 18866
diff changeset
133 }
3cbb0846337c added -G:CompileTheWorldMethodFilter option
Doug Simon <doug.simon@oracle.com>
parents: 18866
diff changeset
134 return false;
3cbb0846337c added -G:CompileTheWorldMethodFilter option
Doug Simon <doug.simon@oracle.com>
parents: 18866
diff changeset
135 }
3cbb0846337c added -G:CompileTheWorldMethodFilter option
Doug Simon <doug.simon@oracle.com>
parents: 18866
diff changeset
136
7318
323ece2b012b Refactor debug environment creation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
137 public MethodFilter(String sourcePattern) {
323ece2b012b Refactor debug environment creation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
138 String pattern = sourcePattern.trim();
323ece2b012b Refactor debug environment creation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
139
323ece2b012b Refactor debug environment creation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
140 // extract parameter part
323ece2b012b Refactor debug environment creation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
141 int pos = pattern.indexOf('(');
323ece2b012b Refactor debug environment creation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
142 if (pos != -1) {
323ece2b012b Refactor debug environment creation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
143 if (pattern.charAt(pattern.length() - 1) != ')') {
323ece2b012b Refactor debug environment creation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
144 throw new IllegalArgumentException("missing ')' at end of method filter pattern: " + pattern);
323ece2b012b Refactor debug environment creation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
145 }
323ece2b012b Refactor debug environment creation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
146 String[] signatureClasses = pattern.substring(pos + 1, pattern.length() - 1).split(";", -1);
323ece2b012b Refactor debug environment creation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
147 signature = new Pattern[signatureClasses.length];
323ece2b012b Refactor debug environment creation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
148 for (int i = 0; i < signatureClasses.length; i++) {
323ece2b012b Refactor debug environment creation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
149 signature[i] = createClassGlobPattern(signatureClasses[i].trim());
323ece2b012b Refactor debug environment creation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
150 }
323ece2b012b Refactor debug environment creation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
151 pattern = pattern.substring(0, pos);
323ece2b012b Refactor debug environment creation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
152 } else {
323ece2b012b Refactor debug environment creation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
153 signature = null;
323ece2b012b Refactor debug environment creation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
154 }
323ece2b012b Refactor debug environment creation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
155
323ece2b012b Refactor debug environment creation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
156 // If there is at least one "." then everything before the last "." is the class name.
323ece2b012b Refactor debug environment creation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
157 // Otherwise, the pattern contains only the method name.
323ece2b012b Refactor debug environment creation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
158 pos = pattern.lastIndexOf('.');
323ece2b012b Refactor debug environment creation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
159 if (pos != -1) {
323ece2b012b Refactor debug environment creation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
160 clazz = createClassGlobPattern(pattern.substring(0, pos));
323ece2b012b Refactor debug environment creation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
161 methodName = Pattern.compile(createGlobString(pattern.substring(pos + 1)));
323ece2b012b Refactor debug environment creation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
162 } else {
323ece2b012b Refactor debug environment creation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
163 clazz = null;
323ece2b012b Refactor debug environment creation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
164 methodName = Pattern.compile(createGlobString(pattern));
323ece2b012b Refactor debug environment creation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
165 }
323ece2b012b Refactor debug environment creation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
166 }
323ece2b012b Refactor debug environment creation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
167
323ece2b012b Refactor debug environment creation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
168 static String createGlobString(String pattern) {
323ece2b012b Refactor debug environment creation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
169 return Pattern.quote(pattern).replace("?", "\\E.\\Q").replace("*", "\\E.*\\Q");
323ece2b012b Refactor debug environment creation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
170 }
323ece2b012b Refactor debug environment creation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
171
323ece2b012b Refactor debug environment creation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
172 private static Pattern createClassGlobPattern(String pattern) {
323ece2b012b Refactor debug environment creation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
173 if (pattern.length() == 0) {
323ece2b012b Refactor debug environment creation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
174 return null;
323ece2b012b Refactor debug environment creation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
175 } else if (pattern.contains(".")) {
323ece2b012b Refactor debug environment creation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
176 return Pattern.compile(createGlobString(pattern));
323ece2b012b Refactor debug environment creation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
177 } else {
20046
116c600253e5 allow unqualified nested class names in the class part of a MethodFilter pattern
Doug Simon <doug.simon@oracle.com>
parents: 20018
diff changeset
178 return Pattern.compile("([^\\.\\$]*[\\.\\$])*" + createGlobString(pattern));
7318
323ece2b012b Refactor debug environment creation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
179 }
323ece2b012b Refactor debug environment creation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
180 }
323ece2b012b Refactor debug environment creation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
181
18866
0d23a97ba488 added MethodFilter.matchesClassName
Doug Simon <doug.simon@oracle.com>
parents: 16479
diff changeset
182 /**
0d23a97ba488 added MethodFilter.matchesClassName
Doug Simon <doug.simon@oracle.com>
parents: 16479
diff changeset
183 * Determines if the class part of this filter matches a given class name.
0d23a97ba488 added MethodFilter.matchesClassName
Doug Simon <doug.simon@oracle.com>
parents: 16479
diff changeset
184 */
0d23a97ba488 added MethodFilter.matchesClassName
Doug Simon <doug.simon@oracle.com>
parents: 16479
diff changeset
185 public boolean matchesClassName(String className) {
0d23a97ba488 added MethodFilter.matchesClassName
Doug Simon <doug.simon@oracle.com>
parents: 16479
diff changeset
186 return clazz == null || clazz.matcher(className).matches();
0d23a97ba488 added MethodFilter.matchesClassName
Doug Simon <doug.simon@oracle.com>
parents: 16479
diff changeset
187 }
0d23a97ba488 added MethodFilter.matchesClassName
Doug Simon <doug.simon@oracle.com>
parents: 16479
diff changeset
188
7318
323ece2b012b Refactor debug environment creation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
189 public boolean matches(JavaMethod o) {
323ece2b012b Refactor debug environment creation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
190 // check method name first, since MetaUtil.toJavaName is expensive
323ece2b012b Refactor debug environment creation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
191 if (methodName != null && !methodName.matcher(o.getName()).matches()) {
323ece2b012b Refactor debug environment creation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
192 return false;
323ece2b012b Refactor debug environment creation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
193 }
16479
558cf39c646b moved toJavaName(JavaType type) from MetaUtil to be a default method in JavaType
Doug Simon <doug.simon@oracle.com>
parents: 14906
diff changeset
194 if (clazz != null && !clazz.matcher(o.getDeclaringClass().toJavaName()).matches()) {
7318
323ece2b012b Refactor debug environment creation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
195 return false;
323ece2b012b Refactor debug environment creation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
196 }
323ece2b012b Refactor debug environment creation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
197 if (signature != null) {
323ece2b012b Refactor debug environment creation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
198 Signature sig = o.getSignature();
323ece2b012b Refactor debug environment creation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
199 if (sig.getParameterCount(false) != signature.length) {
323ece2b012b Refactor debug environment creation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
200 return false;
323ece2b012b Refactor debug environment creation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
201 }
323ece2b012b Refactor debug environment creation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
202 for (int i = 0; i < signature.length; i++) {
323ece2b012b Refactor debug environment creation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
203 JavaType type = sig.getParameterType(i, null);
16479
558cf39c646b moved toJavaName(JavaType type) from MetaUtil to be a default method in JavaType
Doug Simon <doug.simon@oracle.com>
parents: 14906
diff changeset
204 String javaName = type.toJavaName();
7318
323ece2b012b Refactor debug environment creation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
205 if (signature[i] != null && !signature[i].matcher(javaName).matches()) {
323ece2b012b Refactor debug environment creation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
206 return false;
323ece2b012b Refactor debug environment creation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
207 }
323ece2b012b Refactor debug environment creation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
208 }
323ece2b012b Refactor debug environment creation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
209 }
323ece2b012b Refactor debug environment creation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
210 return true;
323ece2b012b Refactor debug environment creation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
211 }
323ece2b012b Refactor debug environment creation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
212
323ece2b012b Refactor debug environment creation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
213 @Override
323ece2b012b Refactor debug environment creation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
214 public String toString() {
323ece2b012b Refactor debug environment creation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
215 StringBuilder buf = new StringBuilder("MethodFilter[");
323ece2b012b Refactor debug environment creation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
216 String sep = "";
323ece2b012b Refactor debug environment creation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
217 if (clazz != null) {
323ece2b012b Refactor debug environment creation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
218 buf.append(sep).append("clazz=").append(clazz);
323ece2b012b Refactor debug environment creation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
219 sep = ", ";
323ece2b012b Refactor debug environment creation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
220 }
323ece2b012b Refactor debug environment creation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
221 if (methodName != null) {
323ece2b012b Refactor debug environment creation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
222 buf.append(sep).append("methodName=").append(methodName);
323ece2b012b Refactor debug environment creation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
223 sep = ", ";
323ece2b012b Refactor debug environment creation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
224 }
323ece2b012b Refactor debug environment creation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
225 if (signature != null) {
323ece2b012b Refactor debug environment creation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
226 buf.append(sep).append("signature=").append(Arrays.toString(signature));
323ece2b012b Refactor debug environment creation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
227 sep = ", ";
323ece2b012b Refactor debug environment creation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
228 }
323ece2b012b Refactor debug environment creation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
229 return buf.append("]").toString();
323ece2b012b Refactor debug environment creation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
230 }
323ece2b012b Refactor debug environment creation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
231 }