src/hotspot/share/compiler/methodMatcher.cpp
author neliasso
Tue, 04 Dec 2018 18:55:06 +0100
changeset 52894 8df9cf767f79
parent 51333 f6641fcf7b7e
child 53162 a242fc65ef2e
permissions -rw-r--r--
8214773: Replace use of thread unsafe strtok Reviewed-by: thartmann, dholmes
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
33069
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
     1
/*
37248
11a660dbbb8e 8132524: Missing includes to resourceArea.hpp
jprovino
parents: 33626
diff changeset
     2
 * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
33069
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
     4
 *
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
     7
 * published by the Free Software Foundation.
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
     8
 *
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
    13
 * accompanied this code).
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
    14
 *
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
    18
 *
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
    21
 * questions.
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
    22
 *
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
    23
 */
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
    24
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
    25
#include "precompiled.hpp"
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
    26
#include "compiler/methodMatcher.hpp"
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
    27
#include "memory/oopFactory.hpp"
37248
11a660dbbb8e 8132524: Missing includes to resourceArea.hpp
jprovino
parents: 33626
diff changeset
    28
#include "memory/resourceArea.hpp"
33069
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
    29
#include "oops/oop.inline.hpp"
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
    30
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
    31
// The JVM specification defines the allowed characters.
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
    32
// Tokens that are disallowed by the JVM specification can have
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
    33
// a meaning to the parser so we need to include them here.
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
    34
// The parser does not enforce all rules of the JVMS - a successful parse
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
    35
// does not mean that it is an allowed name. Illegal names will
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
    36
// be ignored since they never can match a class or method.
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
    37
//
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
    38
// '\0' and 0xf0-0xff are disallowed in constant string values
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
    39
// 0x20 ' ', 0x09 '\t' and, 0x2c ',' are used in the matching
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
    40
// 0x5b '[' and 0x5d ']' can not be used because of the matcher
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
    41
// 0x28 '(' and 0x29 ')' are used for the signature
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
    42
// 0x2e '.' is always replaced before the matching
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
    43
// 0x2f '/' is only used in the class name as package separator
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
    44
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
    45
#define RANGEBASE "\x1\x2\x3\x4\x5\x6\x7\x8\xa\xb\xc\xd\xe\xf" \
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
    46
    "\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f" \
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
    47
    "\x21\x22\x23\x24\x25\x26\x27\x2a\x2b\x2c\x2d" \
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
    48
    "\x30\x31\x32\x33\x34\x35\x36\x37\x38\x39\x3a\x3b\x3c\x3d\x3e\x3f" \
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
    49
    "\x40\x41\x42\x43\x44\x45\x46\x47\x48\x49\x4a\x4b\x4c\x4d\x4e\x4f" \
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
    50
    "\x50\x51\x52\x53\x54\x55\x56\x57\x58\x59\x5a\x5c\x5e\x5f" \
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
    51
    "\x60\x61\x62\x63\x64\x65\x66\x67\x68\x69\x6a\x6b\x6c\x6d\x6e\x6f" \
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
    52
    "\x70\x71\x72\x73\x74\x75\x76\x77\x78\x79\x7a\x7b\x7c\x7d\x7e\x7f" \
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
    53
    "\x80\x81\x82\x83\x84\x85\x86\x87\x88\x89\x8a\x8b\x8c\x8d\x8e\x8f" \
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
    54
    "\x90\x91\x92\x93\x94\x95\x96\x97\x98\x99\x9a\x9b\x9c\x9d\x9e\x9f" \
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
    55
    "\xa0\xa1\xa2\xa3\xa4\xa5\xa6\xa7\xa8\xa9\xaa\xab\xac\xad\xae\xaf" \
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
    56
    "\xb0\xb1\xb2\xb3\xb4\xb5\xb6\xb7\xb8\xb9\xba\xbb\xbc\xbd\xbe\xbf" \
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
    57
    "\xc0\xc1\xc2\xc3\xc4\xc5\xc6\xc7\xc8\xc9\xca\xcb\xcc\xcd\xce\xcf" \
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
    58
    "\xd0\xd1\xd2\xd3\xd4\xd5\xd6\xd7\xd8\xd9\xda\xdb\xdc\xdd\xde\xdf" \
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
    59
    "\xe0\xe1\xe2\xe3\xe4\xe5\xe6\xe7\xe8\xe9\xea\xeb\xec\xed\xee\xef"
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
    60
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
    61
#define RANGE0 "[*" RANGEBASE "]"
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
    62
#define RANGESLASH "[*" RANGEBASE "/]"
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
    63
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
    64
MethodMatcher::MethodMatcher():
51333
f6641fcf7b7e 8208670: Compiler changes to allow enabling -Wreorder
tschatzl
parents: 48000
diff changeset
    65
    _class_name(NULL)
33069
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
    66
  , _method_name(NULL)
51333
f6641fcf7b7e 8208670: Compiler changes to allow enabling -Wreorder
tschatzl
parents: 48000
diff changeset
    67
  , _signature(NULL)
f6641fcf7b7e 8208670: Compiler changes to allow enabling -Wreorder
tschatzl
parents: 48000
diff changeset
    68
  , _class_mode(Exact)
f6641fcf7b7e 8208670: Compiler changes to allow enabling -Wreorder
tschatzl
parents: 48000
diff changeset
    69
  , _method_mode(Exact) {
33069
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
    70
}
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
    71
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
    72
MethodMatcher::~MethodMatcher() {
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
    73
  if (_class_name != NULL) {
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
    74
    _class_name->decrement_refcount();
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
    75
  }
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
    76
  if (_method_name != NULL) {
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
    77
    _method_name->decrement_refcount();
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
    78
  }
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
    79
  if (_signature != NULL) {
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
    80
    _signature->decrement_refcount();
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
    81
  }
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
    82
}
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
    83
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
    84
void MethodMatcher::init(Symbol* class_name, Mode class_mode,
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
    85
                             Symbol* method_name, Mode method_mode,
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
    86
                             Symbol* signature) {
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
    87
 _class_mode = class_mode;
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
    88
 _method_mode = method_mode;
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
    89
 _class_name = class_name;
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
    90
 _method_name = method_name;
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
    91
 _signature = signature;
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
    92
}
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
    93
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
    94
bool MethodMatcher::canonicalize(char * line, const char *& error_msg) {
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
    95
  char* colon = strstr(line, "::");
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
    96
  bool have_colon = (colon != NULL);
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
    97
  if (have_colon) {
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
    98
    // Don't allow multiple '::'
47579
58931d9b2260 8187570: Comparison between pointer and char in MethodMatcher::canonicalize
ehelin
parents: 47216
diff changeset
    99
    if (colon[2] != '\0') {
33069
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
   100
      if (strstr(colon+2, "::")) {
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
   101
        error_msg = "Method pattern only allows one '::' allowed";
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
   102
        return false;
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
   103
      }
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
   104
    }
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
   105
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
   106
    bool in_signature = false;
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
   107
    char* pos = line;
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
   108
    if (pos != NULL) {
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
   109
      for (char* lp = pos + 1; *lp != '\0'; lp++) {
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
   110
        if (*lp == '(') {
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
   111
          break;
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
   112
        }
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
   113
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
   114
        if (*lp == '/') {
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
   115
          error_msg = "Method pattern uses '/' together with '::'";
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
   116
          return false;
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
   117
        }
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
   118
      }
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
   119
    }
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
   120
  } else {
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
   121
    // Don't allow mixed package separators
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
   122
    char* pos = strchr(line, '.');
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
   123
    bool in_signature = false;
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
   124
    if (pos != NULL) {
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
   125
      for (char* lp = pos + 1; *lp != '\0'; lp++) {
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
   126
        if (*lp == '(') {
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
   127
          in_signature = true;
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
   128
        }
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
   129
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
   130
        // After any comma the method pattern has ended
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
   131
        if (*lp == ',') {
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
   132
          break;
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
   133
        }
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
   134
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
   135
        if (!in_signature && (*lp == '/')) {
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
   136
          error_msg = "Method pattern uses mixed '/' and '.' package separators";
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
   137
          return false;
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
   138
        }
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
   139
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
   140
        if (*lp == '.') {
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
   141
          error_msg = "Method pattern uses multiple '.' in pattern";
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
   142
          return false;
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
   143
        }
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
   144
      }
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
   145
    }
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
   146
  }
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
   147
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
   148
  for (char* lp = line; *lp != '\0'; lp++) {
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
   149
    // Allow '.' to separate the class name from the method name.
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
   150
    // This is the preferred spelling of methods:
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
   151
    //      exclude java/lang/String.indexOf(I)I
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
   152
    // Allow ',' for spaces (eases command line quoting).
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
   153
    //      exclude,java/lang/String.indexOf
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
   154
    // For backward compatibility, allow space as separator also.
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
   155
    //      exclude java/lang/String indexOf
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
   156
    //      exclude,java/lang/String,indexOf
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
   157
    // For easy cut-and-paste of method names, allow VM output format
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
   158
    // as produced by Method::print_short_name:
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
   159
    //      exclude java.lang.String::indexOf
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
   160
    // For simple implementation convenience here, convert them all to space.
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
   161
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
   162
    if (have_colon) {
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
   163
      if (*lp == '.')  *lp = '/';   // dots build the package prefix
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
   164
      if (*lp == ':')  *lp = ' ';
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
   165
    }
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
   166
    if (*lp == ',' || *lp == '.')  *lp = ' ';
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
   167
  }
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
   168
  return true;
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
   169
}
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
   170
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
   171
bool MethodMatcher::match(Symbol* candidate, Symbol* match, Mode match_mode) const {
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
   172
  if (match_mode == Any) {
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
   173
    return true;
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
   174
  }
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
   175
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
   176
  if (match_mode == Exact) {
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
   177
    return candidate == match;
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
   178
  }
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
   179
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
   180
  ResourceMark rm;
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
   181
  const char * candidate_string = candidate->as_C_string();
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
   182
  const char * match_string = match->as_C_string();
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
   183
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
   184
  switch (match_mode) {
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
   185
  case Prefix:
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
   186
    return strstr(candidate_string, match_string) == candidate_string;
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
   187
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
   188
  case Suffix: {
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
   189
    size_t clen = strlen(candidate_string);
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
   190
    size_t mlen = strlen(match_string);
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
   191
    return clen >= mlen && strcmp(candidate_string + clen - mlen, match_string) == 0;
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
   192
  }
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
   193
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
   194
  case Substring:
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
   195
    return strstr(candidate_string, match_string) != NULL;
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
   196
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
   197
  default:
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
   198
    return false;
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
   199
  }
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
   200
}
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
   201
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
   202
static MethodMatcher::Mode check_mode(char name[], const char*& error_msg) {
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
   203
  int match = MethodMatcher::Exact;
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
   204
  if (name[0] == '*') {
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
   205
    if (strlen(name) == 1) {
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
   206
      return MethodMatcher::Any;
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
   207
    }
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
   208
    match |= MethodMatcher::Suffix;
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
   209
    memmove(name, name + 1, strlen(name + 1) + 1);
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
   210
  }
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
   211
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
   212
  size_t len = strlen(name);
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
   213
  if (len > 0 && name[len - 1] == '*') {
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
   214
    match |= MethodMatcher::Prefix;
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
   215
    name[--len] = '\0';
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
   216
  }
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
   217
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
   218
  if (strlen(name) == 0) {
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
   219
    error_msg = "** Not a valid pattern";
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
   220
    return MethodMatcher::Any;
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
   221
  }
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
   222
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
   223
  if (strstr(name, "*") != NULL) {
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
   224
    error_msg = " Embedded * not allowed";
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
   225
    return MethodMatcher::Unknown;
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
   226
  }
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
   227
  return (MethodMatcher::Mode)match;
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
   228
}
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
   229
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
   230
// Skip any leading spaces
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
   231
void skip_leading_spaces(char*& line, int* total_bytes_read ) {
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
   232
  int bytes_read = 0;
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
   233
  sscanf(line, "%*[ \t]%n", &bytes_read);
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
   234
  if (bytes_read > 0) {
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
   235
    line += bytes_read;
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
   236
    *total_bytes_read += bytes_read;
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
   237
  }
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
   238
}
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
   239
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
   240
void MethodMatcher::parse_method_pattern(char*& line, const char*& error_msg, MethodMatcher* matcher) {
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
   241
  MethodMatcher::Mode c_match;
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
   242
  MethodMatcher::Mode m_match;
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
   243
  char class_name[256] = {0};
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
   244
  char method_name[256] = {0};
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
   245
  char sig[1024] = {0};
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
   246
  int bytes_read = 0;
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
   247
  int total_bytes_read = 0;
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
   248
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
   249
  assert(error_msg == NULL, "Dont call here with error_msg already set");
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
   250
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
   251
  if (!MethodMatcher::canonicalize(line, error_msg)) {
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
   252
    assert(error_msg != NULL, "Message must be set if parsing failed");
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
   253
    return;
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
   254
  }
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
   255
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
   256
  skip_leading_spaces(line, &total_bytes_read);
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
   257
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
   258
  if (2 == sscanf(line, "%255" RANGESLASH "%*[ ]" "%255"  RANGE0 "%n", class_name, method_name, &bytes_read)) {
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
   259
    c_match = check_mode(class_name, error_msg);
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
   260
    m_match = check_mode(method_name, error_msg);
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
   261
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
   262
    if ((strchr(class_name, '<') != NULL) || (strchr(class_name, '>') != NULL)) {
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
   263
      error_msg = "Chars '<' and '>' not allowed in class name";
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
   264
      return;
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
   265
    }
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
   266
    if ((strchr(method_name, '<') != NULL) || (strchr(method_name, '>') != NULL)) {
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
   267
      if ((strncmp("<init>", method_name, 255) != 0) && (strncmp("<clinit>", method_name, 255) != 0)) {
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
   268
        error_msg = "Chars '<' and '>' only allowed in <init> and <clinit>";
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
   269
        return;
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
   270
      }
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
   271
    }
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
   272
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
   273
    if (c_match == MethodMatcher::Unknown || m_match == MethodMatcher::Unknown) {
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
   274
      assert(error_msg != NULL, "Must have been set by check_mode()");
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
   275
      return;
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
   276
    }
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
   277
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
   278
    EXCEPTION_MARK;
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
   279
    Symbol* signature = NULL;
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
   280
    line += bytes_read;
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
   281
    bytes_read = 0;
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
   282
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
   283
    skip_leading_spaces(line, &total_bytes_read);
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
   284
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
   285
    // there might be a signature following the method.
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
   286
    // signatures always begin with ( so match that by hand
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
   287
    if (line[0] == '(') {
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
   288
      line++;
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
   289
      sig[0] = '(';
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
   290
      // scan the rest
48000
089b6bf0d1a7 8160303: parse_method_pattern only scans 254 chars
neliasso
parents: 47579
diff changeset
   291
      if (1 == sscanf(line, "%1022[[);/" RANGEBASE "]%n", sig+1, &bytes_read)) {
33069
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
   292
        if (strchr(sig, '*') != NULL) {
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
   293
          error_msg = " Wildcard * not allowed in signature";
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
   294
          return;
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
   295
        }
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
   296
        line += bytes_read;
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
   297
      }
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
   298
      signature = SymbolTable::new_symbol(sig, CHECK);
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
   299
    }
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
   300
    Symbol* c_name = SymbolTable::new_symbol(class_name, CHECK);
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
   301
    Symbol* m_name = SymbolTable::new_symbol(method_name, CHECK);
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
   302
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
   303
    matcher->init(c_name, c_match, m_name, m_match, signature);
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
   304
    return;
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
   305
  } else {
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
   306
    error_msg = "Could not parse method pattern";
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
   307
  }
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
   308
}
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
   309
33593
60764a78fa5c 8140274: methodHandles and constantPoolHandles should be passed as const references
coleenp
parents: 33069
diff changeset
   310
bool MethodMatcher::matches(const methodHandle& method) const {
33069
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
   311
  Symbol* class_name  = method->method_holder()->name();
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
   312
  Symbol* method_name = method->name();
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
   313
  Symbol* signature = method->signature();
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
   314
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
   315
  if (match(class_name, this->class_name(), _class_mode) &&
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
   316
      match(method_name, this->method_name(), _method_mode) &&
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
   317
      ((this->signature() == NULL) || match(signature, this->signature(), Prefix))) {
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
   318
    return true;
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
   319
  }
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
   320
  return false;
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
   321
}
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
   322
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
   323
void MethodMatcher::print_symbol(outputStream* st, Symbol* h, Mode mode) {
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
   324
  if (mode == Suffix || mode == Substring || mode == Any) {
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
   325
    st->print("*");
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
   326
  }
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
   327
  if (mode != Any) {
33468
b82c87453d2d 8139996: CompileCommand prints quoted ascii strings
neliasso
parents: 33451
diff changeset
   328
    h->print_utf8_on(st);
33069
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
   329
  }
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
   330
  if (mode == Prefix || mode == Substring) {
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
   331
    st->print("*");
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
   332
  }
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
   333
}
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
   334
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
   335
void MethodMatcher::print_base(outputStream* st) {
33468
b82c87453d2d 8139996: CompileCommand prints quoted ascii strings
neliasso
parents: 33451
diff changeset
   336
  ResourceMark rm;
b82c87453d2d 8139996: CompileCommand prints quoted ascii strings
neliasso
parents: 33451
diff changeset
   337
33069
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
   338
  print_symbol(st, class_name(), _class_mode);
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
   339
  st->print(".");
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
   340
  print_symbol(st, method_name(), _method_mode);
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
   341
  if (signature() != NULL) {
33468
b82c87453d2d 8139996: CompileCommand prints quoted ascii strings
neliasso
parents: 33451
diff changeset
   342
    signature()->print_utf8_on(st);
33069
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
   343
  }
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
   344
}
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
   345
33451
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents: 33069
diff changeset
   346
BasicMatcher* BasicMatcher::parse_method_pattern(char* line, const char*& error_msg) {
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents: 33069
diff changeset
   347
  assert(error_msg == NULL, "Don't call here with error_msg already set");
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents: 33069
diff changeset
   348
  BasicMatcher* bm = new BasicMatcher();
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents: 33069
diff changeset
   349
  MethodMatcher::parse_method_pattern(line, error_msg, bm);
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents: 33069
diff changeset
   350
  if (error_msg != NULL) {
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents: 33069
diff changeset
   351
    delete bm;
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents: 33069
diff changeset
   352
    return NULL;
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents: 33069
diff changeset
   353
  }
33069
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
   354
33451
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents: 33069
diff changeset
   355
  // check for bad trailing characters
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents: 33069
diff changeset
   356
  int bytes_read = 0;
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents: 33069
diff changeset
   357
  sscanf(line, "%*[ \t]%n", &bytes_read);
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents: 33069
diff changeset
   358
  if (line[bytes_read] != '\0') {
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents: 33069
diff changeset
   359
    error_msg = "Unrecognized trailing text after method pattern";
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents: 33069
diff changeset
   360
    delete bm;
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents: 33069
diff changeset
   361
    return NULL;
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents: 33069
diff changeset
   362
  }
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents: 33069
diff changeset
   363
  return bm;
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents: 33069
diff changeset
   364
}
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents: 33069
diff changeset
   365
33626
jwilhelm
parents: 33593 33468
diff changeset
   366
bool BasicMatcher::match(const methodHandle& method) {
33451
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents: 33069
diff changeset
   367
  for (BasicMatcher* current = this; current != NULL; current = current->next()) {
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents: 33069
diff changeset
   368
    if (current->matches(method)) {
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents: 33069
diff changeset
   369
      return true;
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents: 33069
diff changeset
   370
    }
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents: 33069
diff changeset
   371
  }
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents: 33069
diff changeset
   372
  return false;
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents: 33069
diff changeset
   373
}
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents: 33069
diff changeset
   374
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents: 33069
diff changeset
   375
void InlineMatcher::print(outputStream* st) {
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents: 33069
diff changeset
   376
  if (_inline_action == InlineMatcher::force_inline) {
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents: 33069
diff changeset
   377
    st->print("+");
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents: 33069
diff changeset
   378
  } else {
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents: 33069
diff changeset
   379
    st->print("-");
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents: 33069
diff changeset
   380
  }
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents: 33069
diff changeset
   381
  print_base(st);
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents: 33069
diff changeset
   382
}
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents: 33069
diff changeset
   383
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents: 33069
diff changeset
   384
InlineMatcher* InlineMatcher::parse_method_pattern(char* line, const char*& error_msg) {
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents: 33069
diff changeset
   385
  assert(error_msg == NULL, "Dont call here with error_msg already set");
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents: 33069
diff changeset
   386
  InlineMatcher* im = new InlineMatcher();
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents: 33069
diff changeset
   387
  MethodMatcher::parse_method_pattern(line, error_msg, im);
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents: 33069
diff changeset
   388
  if (error_msg != NULL) {
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents: 33069
diff changeset
   389
    delete im;
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents: 33069
diff changeset
   390
    return NULL;
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents: 33069
diff changeset
   391
  }
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents: 33069
diff changeset
   392
  return im;
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents: 33069
diff changeset
   393
}
33069
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
   394
33626
jwilhelm
parents: 33593 33468
diff changeset
   395
bool InlineMatcher::match(const methodHandle& method, int inline_action) {
33451
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents: 33069
diff changeset
   396
  for (InlineMatcher* current = this; current != NULL; current = current->next()) {
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents: 33069
diff changeset
   397
    if (current->matches(method)) {
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents: 33069
diff changeset
   398
      return (current->_inline_action == inline_action);
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents: 33069
diff changeset
   399
    }
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents: 33069
diff changeset
   400
  }
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents: 33069
diff changeset
   401
  return false;
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents: 33069
diff changeset
   402
}
33069
d8eed614f298 8135068: Extract method matchers from CompilerOracle
neliasso
parents:
diff changeset
   403
33451
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents: 33069
diff changeset
   404
InlineMatcher* InlineMatcher::parse_inline_pattern(char* str, const char*& error_msg) {
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents: 33069
diff changeset
   405
  // check first token is +/-
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents: 33069
diff changeset
   406
  InlineType _inline_action;
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents: 33069
diff changeset
   407
   switch (str[0]) {
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents: 33069
diff changeset
   408
   case '-':
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents: 33069
diff changeset
   409
     _inline_action = InlineMatcher::dont_inline;
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents: 33069
diff changeset
   410
     break;
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents: 33069
diff changeset
   411
   case '+':
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents: 33069
diff changeset
   412
     _inline_action = InlineMatcher::force_inline;
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents: 33069
diff changeset
   413
     break;
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents: 33069
diff changeset
   414
   default:
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents: 33069
diff changeset
   415
     error_msg = "Missing leading inline type (+/-)";
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents: 33069
diff changeset
   416
     return NULL;
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents: 33069
diff changeset
   417
   }
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents: 33069
diff changeset
   418
   str++;
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents: 33069
diff changeset
   419
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents: 33069
diff changeset
   420
   int bytes_read = 0;
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents: 33069
diff changeset
   421
   assert(error_msg== NULL, "error_msg must not be set yet");
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents: 33069
diff changeset
   422
   InlineMatcher* im = InlineMatcher::parse_method_pattern(str, error_msg);
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents: 33069
diff changeset
   423
   if (im == NULL) {
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents: 33069
diff changeset
   424
     assert(error_msg != NULL, "Must have error message");
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents: 33069
diff changeset
   425
     return NULL;
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents: 33069
diff changeset
   426
   }
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents: 33069
diff changeset
   427
   im->set_action(_inline_action);
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents: 33069
diff changeset
   428
   return im;
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents: 33069
diff changeset
   429
}
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents: 33069
diff changeset
   430
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents: 33069
diff changeset
   431
InlineMatcher* InlineMatcher::clone() {
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents: 33069
diff changeset
   432
   InlineMatcher* m = new InlineMatcher();
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents: 33069
diff changeset
   433
   m->_class_mode =  _class_mode;
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents: 33069
diff changeset
   434
   m->_method_mode = _method_mode;
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents: 33069
diff changeset
   435
   m->_inline_action = _inline_action;
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents: 33069
diff changeset
   436
   m->_class_name = _class_name;
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents: 33069
diff changeset
   437
   if(_class_name != NULL) {
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents: 33069
diff changeset
   438
     _class_name->increment_refcount();
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents: 33069
diff changeset
   439
   }
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents: 33069
diff changeset
   440
   m->_method_name = _method_name;
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents: 33069
diff changeset
   441
   if (_method_name != NULL) {
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents: 33069
diff changeset
   442
     _method_name->increment_refcount();
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents: 33069
diff changeset
   443
   }
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents: 33069
diff changeset
   444
   m->_signature = _signature;
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents: 33069
diff changeset
   445
   if (_signature != NULL) {
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents: 33069
diff changeset
   446
     _signature->increment_refcount();
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents: 33069
diff changeset
   447
   }
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents: 33069
diff changeset
   448
   return m;
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents: 33069
diff changeset
   449
}