hotspot/src/share/vm/code/oopRecorder.hpp
author twisti
Tue, 24 Jul 2012 10:51:00 -0700
changeset 13391 30245956af37
parent 7397 5b173b4ca846
child 13728 882756847a04
permissions -rw-r--r--
7023639: JSR 292 method handle invocation needs a fast path for compiled code 6984705: JSR 292 method handle creation should not go through JNI Summary: remove assembly code for JDK 7 chained method handles Reviewed-by: jrose, twisti, kvn, mhaupt Contributed-by: John Rose <john.r.rose@oracle.com>, Christian Thalinger <christian.thalinger@oracle.com>, Michael Haupt <michael.haupt@oracle.com>
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
5702
jrose
parents: 5547 5686
diff changeset
     2
 * Copyright (c) 1998, 2010, 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: 5702
diff changeset
    25
#ifndef SHARE_VM_CODE_OOPRECORDER_HPP
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5702
diff changeset
    26
#define SHARE_VM_CODE_OOPRECORDER_HPP
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5702
diff changeset
    27
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5702
diff changeset
    28
#include "runtime/handles.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5702
diff changeset
    29
#include "utilities/growableArray.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5702
diff changeset
    30
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    31
// Recording and retrieval of oop relocations in compiled code.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    32
489c9b5090e2 Initial load
duke
parents:
diff changeset
    33
class CodeBlob;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    34
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
class OopRecorder : public ResourceObj {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
  // A two-way mapping from positive indexes to oop handles.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
  // The zero index is reserved for a constant (sharable) null.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
  // Indexes may not be negative.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
  // Use the given arena to manage storage, if not NULL.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
  // By default, uses the current ResourceArea.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
  OopRecorder(Arena* arena = NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
  // Generate a new index on which CodeBlob::oop_addr_at will work.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
  // allocate_index and find_index never return the same index,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
  // and allocate_index never returns the same index twice.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
  // In fact, two successive calls to allocate_index return successive ints.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
  int allocate_index(jobject h) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
    return add_handle(h, false);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
  // For a given jobject, this will return the same index repeatedly.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
  // The index can later be given to oop_at to retrieve the oop.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
  // However, the oop must not be changed via CodeBlob::oop_addr_at.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
  int find_index(jobject h) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
    int index = maybe_find_index(h);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
    if (index < 0) {  // previously unallocated
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
      index = add_handle(h, true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
    return index;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
  // variant of find_index which does not allocate if not found (yields -1)
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
  int maybe_find_index(jobject h);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
  // returns the size of the generated oop table, for sizing the CodeBlob.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
  // must be called after all oops are allocated!
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
  int oop_size();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
  // Retrieve the oop handle at a given index.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
  jobject handle_at(int index);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
  int element_count() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
    // there is always a NULL virtually present as first object
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
    return _handles->length() + first_index;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
5686
5435e77aa3df 6951083: oops and relocations should part of nmethod not CodeBlob
twisti
parents: 1
diff changeset
    79
  // copy the generated oop table to nmethod
5435e77aa3df 6951083: oops and relocations should part of nmethod not CodeBlob
twisti
parents: 1
diff changeset
    80
  void copy_to(nmethod* nm);  // => nm->copy_oops(_handles)
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
  bool is_unused() { return _handles == NULL && !_complete; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
#ifdef ASSERT
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
  bool is_complete() { return _complete; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
 private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
  // leaky hash table of handle => index, to help detect duplicate insertion
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
  class IndexCache: public ResourceObj {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
    // This class is only used by the OopRecorder class.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
    friend class OopRecorder;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
    enum {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
      _log_cache_size = 9,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
      _cache_size = (1<<_log_cache_size),
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
      // Index entries are ints.  The LSBit is a collision indicator.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
      _collision_bit_shift = 0,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
      _collision_bit = 1,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
      _index_shift = _collision_bit_shift+1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
    };
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
    int _cache[_cache_size];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
    static juint cache_index(jobject handle) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
      juint ci = (int) (intptr_t) handle;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
      ci ^= ci >> (BitsPerByte*2);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
      ci += ci >> (BitsPerByte*1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
      return ci & (_cache_size-1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
    int* cache_location(jobject handle) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
      return &_cache[ cache_index(handle) ];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
    static bool cache_location_collision(int* cloc) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
      return ((*cloc) & _collision_bit) != 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
    static int cache_location_index(int* cloc) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
      return (*cloc) >> _index_shift;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
    static void set_cache_location_index(int* cloc, int index) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
      int cval0 = (*cloc);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
      int cval1 = (index << _index_shift);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
      if (cval0 != 0 && cval1 != cval0)  cval1 += _collision_bit;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
      (*cloc) = cval1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
    IndexCache();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
  };
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
  // Helper function; returns false for NULL or Universe::non_oop_word().
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
  inline bool is_real_jobject(jobject h);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
  void maybe_initialize();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
  int add_handle(jobject h, bool make_findable);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
  enum { null_index = 0, first_index = 1, index_cache_threshold = 20 };
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
  GrowableArray<jobject>*   _handles;  // ordered list (first is always NULL)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
  GrowableArray<int>*       _no_finds; // all unfindable indexes; usually empty
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
  IndexCache*               _indexes;  // map: jobject -> its probable index
489c9b5090e2 Initial load
duke
parents:
diff changeset
   136
  Arena*                    _arena;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   137
  bool                      _complete;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   138
489c9b5090e2 Initial load
duke
parents:
diff changeset
   139
#ifdef ASSERT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   140
  static int _find_index_calls, _hit_indexes, _missed_indexes;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   141
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
   142
};
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5702
diff changeset
   143
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5702
diff changeset
   144
#endif // SHARE_VM_CODE_OOPRECORDER_HPP