hotspot/src/share/vm/prims/methodComparator.hpp
author aeriksso
Wed, 22 Oct 2014 13:59:56 +0200
changeset 27401 a4697c9502cb
parent 13728 882756847a04
child 36092 b1bf903783b8
permissions -rw-r--r--
8057043: Type annotations not retained during class redefine / retransform Reviewed-by: coleenp, sspitsyn, jfranck
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 7397
diff changeset
     2
 * Copyright (c) 2000, 2012, Oracle and/or its affiliates. All rights reserved.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     4
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
489c9b5090e2 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
489c9b5090e2 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     8
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
489c9b5090e2 Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
489c9b5090e2 Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
489c9b5090e2 Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
489c9b5090e2 Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
489c9b5090e2 Initial load
duke
parents:
diff changeset
    14
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
489c9b5090e2 Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    18
 *
5547
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 1
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 1
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 1
diff changeset
    21
 * questions.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    22
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    23
 */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    24
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 7114
diff changeset
    25
#ifndef SHARE_VM_PRIMS_METHODCOMPARATOR_HPP
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 7114
diff changeset
    26
#define SHARE_VM_PRIMS_METHODCOMPARATOR_HPP
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 7114
diff changeset
    27
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 7114
diff changeset
    28
#include "interpreter/bytecodeStream.hpp"
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 7397
diff changeset
    29
#include "oops/constantPool.hpp"
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 7397
diff changeset
    30
#include "oops/method.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 7114
diff changeset
    31
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    32
class BciMap;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    33
489c9b5090e2 Initial load
duke
parents:
diff changeset
    34
// methodComparator provides an interface for determining if methods of
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
// different versions of classes are equivalent or switchable
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
class MethodComparator {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
 private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
  static BytecodeStream *_s_old, *_s_new;
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 7397
diff changeset
    40
  static ConstantPool* _old_cp;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 7397
diff changeset
    41
  static ConstantPool* _new_cp;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
  static BciMap *_bci_map;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
  static bool _switchable_test;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
  static GrowableArray<int> *_fwd_jmps;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
  static bool args_same(Bytecodes::Code c_old, Bytecodes::Code c_new);
7114
65d21c4c6337 6984311: JSR 292 needs optional bootstrap method parameters
jrose
parents: 5547
diff changeset
    47
  static bool pool_constants_same(int cpi_old, int cpi_new);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 7397
diff changeset
    48
  static int check_stack_and_locals_size(Method* old_method, Method* new_method);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
  // Check if the new method is equivalent to the old one modulo constant pool (EMCP).
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
  // Intuitive definition: two versions of the same method are EMCP, if they don't differ
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
  // on the source code level. Practically, we check whether the only difference between
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
  // method versions is some constantpool indices embedded into the bytecodes, and whether
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
  // these indices eventually point to the same constants for both method versions.
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 7397
diff changeset
    56
  static bool methods_EMCP(Method* old_method, Method* new_method);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 7397
diff changeset
    58
  static bool methods_switchable(Method* old_method, Method* new_method, BciMap &bci_map);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
// ByteCode Index Map. For two versions of the same method, where the new version may contain
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
// fragments not found in the old version, provides a mapping from an index of a bytecode in
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
// the old method to the index of the same bytecode in the new method.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
class BciMap {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
 private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
  int *_old_bci, *_new_st_bci, *_new_end_bci;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
  int _cur_size, _cur_pos;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
  int _pos;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
  BciMap() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
    _cur_size = 50;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
    _old_bci = (int*) malloc(sizeof(int) * _cur_size);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
    _new_st_bci = (int*) malloc(sizeof(int) * _cur_size);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
    _new_end_bci = (int*) malloc(sizeof(int) * _cur_size);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
    _cur_pos = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
  ~BciMap() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
    free(_old_bci);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
    free(_new_st_bci);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
    free(_new_end_bci);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
  // Store the position of an added fragment, e.g.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
  //
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
  //                              |<- old_bci
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
  // -----------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
  // Old method   |invokevirtual 5|aload 1|...
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
  // -----------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
  //
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
  //                                 |<- new_st_bci          |<- new_end_bci
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
  // --------------------------------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
  // New method       |invokevirual 5|aload 2|invokevirtual 6|aload 1|...
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
  // --------------------------------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
  //                                 ^^^^^^^^^^^^^^^^^^^^^^^^
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
  //                                    Added fragment
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
  void store_fragment_location(int old_bci, int new_st_bci, int new_end_bci) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
    if (_cur_pos == _cur_size) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
      _cur_size += 10;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
      _old_bci = (int*) realloc(_old_bci, sizeof(int) * _cur_size);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
      _new_st_bci = (int*) realloc(_new_st_bci, sizeof(int) * _cur_size);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
      _new_end_bci = (int*) realloc(_new_end_bci, sizeof(int) * _cur_size);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
    _old_bci[_cur_pos] = old_bci;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
    _new_st_bci[_cur_pos] = new_st_bci;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
    _new_end_bci[_cur_pos] = new_end_bci;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
    _cur_pos++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
  int new_bci_for_old(int old_bci) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
    if (_cur_pos == 0 || old_bci < _old_bci[0]) return old_bci;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
    _pos = 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
    while (_pos < _cur_pos && old_bci >= _old_bci[_pos])
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
      _pos++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
    return _new_end_bci[_pos-1] + (old_bci - _old_bci[_pos-1]);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
  // Test if two indexes - one in the old method and another in the new one - correspond
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
  // to the same bytecode
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
  bool old_and_new_locations_same(int old_dest_bci, int new_dest_bci) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
    if (new_bci_for_old(old_dest_bci) == new_dest_bci)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
      return true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
    else if (_old_bci[_pos-1] == old_dest_bci)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
      return (new_dest_bci == _new_st_bci[_pos-1]);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
    else return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
};
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 7114
diff changeset
   132
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 7114
diff changeset
   133
#endif // SHARE_VM_PRIMS_METHODCOMPARATOR_HPP