src/share/vm/interpreter/rewriter.hpp

changeset 4037
da91efe96a93
parent 3969
1d7922586cf6
child 4133
f6b0eb4e44cf
     1.1 --- a/src/share/vm/interpreter/rewriter.hpp	Fri Aug 31 16:39:35 2012 -0700
     1.2 +++ b/src/share/vm/interpreter/rewriter.hpp	Sat Sep 01 13:25:18 2012 -0400
     1.3 @@ -1,5 +1,5 @@
     1.4  /*
     1.5 - * Copyright (c) 1998, 2010, Oracle and/or its affiliates. All rights reserved.
     1.6 + * Copyright (c) 1998, 2012, Oracle and/or its affiliates. All rights reserved.
     1.7   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     1.8   *
     1.9   * This code is free software; you can redistribute it and/or modify it
    1.10 @@ -36,59 +36,121 @@
    1.11   private:
    1.12    instanceKlassHandle _klass;
    1.13    constantPoolHandle  _pool;
    1.14 -  objArrayHandle      _methods;
    1.15 +  Array<Method*>*     _methods;
    1.16    intArray            _cp_map;
    1.17 -  intStack            _cp_cache_map;
    1.18 +  intStack            _cp_cache_map;        // for Methodref, Fieldref,
    1.19 +                                            // InterfaceMethodref and InvokeDynamic
    1.20 +  intArray            _reference_map;       // maps from cp index to resolved_refs index (or -1)
    1.21 +  intStack            _resolved_references_map;    // for strings, methodHandle, methodType
    1.22 +  intStack            _invokedynamic_references_map; // for invokedynamic resolved refs
    1.23    intArray            _method_handle_invokers;
    1.24 +  int                 _resolved_reference_limit;
    1.25  
    1.26 -  void init_cp_map(int length) {
    1.27 +  void init_maps(int length) {
    1.28      _cp_map.initialize(length, -1);
    1.29      // Choose an initial value large enough that we don't get frequent
    1.30      // calls to grow().
    1.31      _cp_cache_map.initialize(length / 2);
    1.32 +    // Also cache resolved objects, in another different cache.
    1.33 +    _reference_map.initialize(length, -1);
    1.34 +    _resolved_references_map.initialize(length / 2);
    1.35 +    _invokedynamic_references_map.initialize(length / 2);
    1.36 +    _resolved_reference_limit = -1;
    1.37 +    DEBUG_ONLY(_cp_cache_index_limit = -1);
    1.38    }
    1.39 +
    1.40 +  int _cp_cache_index_limit;
    1.41 +  void record_map_limits() {
    1.42 +#ifdef ASSERT
    1.43 +    // Record initial size of the two arrays generated for the CP cache:
    1.44 +    _cp_cache_index_limit = _cp_cache_map.length();
    1.45 +#endif //ASSERT
    1.46 +    _resolved_reference_limit = _resolved_references_map.length();
    1.47 +  }
    1.48 +
    1.49    int  cp_entry_to_cp_cache(int i) { assert(has_cp_cache(i), "oob"); return _cp_map[i]; }
    1.50    bool has_cp_cache(int i) { return (uint)i < (uint)_cp_map.length() && _cp_map[i] >= 0; }
    1.51 -  int maybe_add_cp_cache_entry(int i) { return has_cp_cache(i) ? _cp_map[i] : add_cp_cache_entry(i); }
    1.52 +
    1.53    int add_cp_cache_entry(int cp_index) {
    1.54 -    assert((cp_index & _secondary_entry_tag) == 0, "bad tag");
    1.55 +    assert(_pool->tag_at(cp_index).value() != JVM_CONSTANT_InvokeDynamic, "use indy version");
    1.56      assert(_cp_map[cp_index] == -1, "not twice on same cp_index");
    1.57 +    assert(_cp_cache_index_limit == -1, "do not add cache entries after first iteration");
    1.58      int cache_index = _cp_cache_map.append(cp_index);
    1.59      _cp_map.at_put(cp_index, cache_index);
    1.60      assert(cp_entry_to_cp_cache(cp_index) == cache_index, "");
    1.61 +    assert(cp_cache_entry_pool_index(cache_index) == cp_index, "");
    1.62      return cache_index;
    1.63    }
    1.64 -  int add_secondary_cp_cache_entry(int main_cpc_entry) {
    1.65 -    assert(main_cpc_entry < _cp_cache_map.length(), "must be earlier CP cache entry");
    1.66 -    int cache_index = _cp_cache_map.append(main_cpc_entry | _secondary_entry_tag);
    1.67 +
    1.68 +  // add a new CP cache entry beyond the normal cache (for invokedynamic only)
    1.69 +  int add_invokedynamic_cp_cache_entry(int cp_index) {
    1.70 +    assert(_pool->tag_at(cp_index).value() == JVM_CONSTANT_InvokeDynamic, "use non-indy version");
    1.71 +    assert(_cp_map[cp_index] == -1, "do not map from cp_index");
    1.72 +    assert(_cp_cache_index_limit >= 0, "add indy cache entries after first iteration");
    1.73 +    int cache_index = _cp_cache_map.append(cp_index);
    1.74 +    assert(cache_index >= _cp_cache_index_limit, "");
    1.75 +    // do not update _cp_map, since the mapping is one-to-many
    1.76 +    assert(cp_cache_entry_pool_index(cache_index) == cp_index, "");
    1.77      return cache_index;
    1.78    }
    1.79  
    1.80 +  // fix duplicated code later
    1.81 +  int  cp_entry_to_resolved_references(int cp_index) const {
    1.82 +    assert(has_entry_in_resolved_references(cp_index), "oob");
    1.83 +    return _reference_map[cp_index];
    1.84 +  }
    1.85 +  bool has_entry_in_resolved_references(int cp_index) const {
    1.86 +    return (uint)cp_index < (uint)_reference_map.length() && _reference_map[cp_index] >= 0;
    1.87 +  }
    1.88 +
    1.89 +  // add a new entry to the resolved_references map
    1.90 +  int add_resolved_references_entry(int cp_index) {
    1.91 +    assert(_reference_map[cp_index] == -1, "not twice on same cp_index");
    1.92 +    assert(_resolved_reference_limit == -1, "do not add CP refs after first iteration");
    1.93 +    int ref_index = _resolved_references_map.append(cp_index);
    1.94 +    _reference_map.at_put(cp_index, ref_index);
    1.95 +    assert(cp_entry_to_resolved_references(cp_index) == ref_index, "");
    1.96 +    return ref_index;
    1.97 +  }
    1.98 +
    1.99 +  // add a new entry to the resolved_references map (for invokedynamic only)
   1.100 +  int add_invokedynamic_resolved_references_entry(int cp_index, int cache_index) {
   1.101 +    assert(_resolved_reference_limit >= 0, "must add indy refs after first iteration");
   1.102 +    int ref_index = _resolved_references_map.append(cp_index);  // many-to-one
   1.103 +    assert(ref_index >= _resolved_reference_limit, "");
   1.104 +    _invokedynamic_references_map.at_put_grow(ref_index, cache_index, -1);
   1.105 +    return ref_index;
   1.106 +  }
   1.107 +
   1.108 +  int resolved_references_entry_to_pool_index(int ref_index) {
   1.109 +    int cp_index = _resolved_references_map[ref_index];
   1.110 +    return cp_index;
   1.111 +  }
   1.112 +
   1.113 +  // invokedynamic support - append the cpCache entry (encoded) in object map.
   1.114 +  // The resolved_references_map should still be in ascending order
   1.115 +  // The resolved_references has the invokedynamic call site objects appended after
   1.116 +  // the objects that are resolved in the constant pool.
   1.117 +  int add_callsite_entry(int main_cpc_entry) {
   1.118 +    int ref_index = _resolved_references_map.append(main_cpc_entry);
   1.119 +    return ref_index;
   1.120 +  }
   1.121 +
   1.122    // Access the contents of _cp_cache_map to determine CP cache layout.
   1.123    int cp_cache_entry_pool_index(int cache_index) {
   1.124      int cp_index = _cp_cache_map[cache_index];
   1.125 -    if ((cp_index & _secondary_entry_tag) != 0)
   1.126 -      return -1;
   1.127 -    else
   1.128        return cp_index;
   1.129    }
   1.130 -  int cp_cache_secondary_entry_main_index(int cache_index) {
   1.131 -    int cp_index = _cp_cache_map[cache_index];
   1.132 -    if ((cp_index & _secondary_entry_tag) == 0)
   1.133 -      return -1;
   1.134 -    else
   1.135 -      return (cp_index - _secondary_entry_tag);
   1.136 -  }
   1.137  
   1.138    // All the work goes in here:
   1.139 -  Rewriter(instanceKlassHandle klass, constantPoolHandle cpool, objArrayHandle methods, TRAPS);
   1.140 +  Rewriter(instanceKlassHandle klass, constantPoolHandle cpool, Array<Method*>* methods, TRAPS);
   1.141  
   1.142    void compute_index_maps();
   1.143    void make_constant_pool_cache(TRAPS);
   1.144 -  void scan_method(methodOop m, bool reverse = false);
   1.145 +  void scan_method(Method* m, bool reverse = false);
   1.146    void rewrite_Object_init(methodHandle m, TRAPS);
   1.147    void rewrite_member_reference(address bcp, int offset, bool reverse = false);
   1.148 -  void maybe_rewrite_invokehandle(address opc, int cp_index, bool reverse = false);
   1.149 +  void maybe_rewrite_invokehandle(address opc, int cp_index, int cache_index, bool reverse = false);
   1.150    void rewrite_invokedynamic(address bcp, int offset, bool reverse = false);
   1.151    void maybe_rewrite_ldc(address bcp, int offset, bool is_wide, bool reverse = false);
   1.152    // Revert bytecodes in case of an exception.
   1.153 @@ -98,17 +160,13 @@
   1.154   public:
   1.155    // Driver routine:
   1.156    static void rewrite(instanceKlassHandle klass, TRAPS);
   1.157 -  static void rewrite(instanceKlassHandle klass, constantPoolHandle cpool, objArrayHandle methods, TRAPS);
   1.158 -
   1.159 -  enum {
   1.160 -    _secondary_entry_tag = nth_bit(30)
   1.161 -  };
   1.162 +  static void rewrite(instanceKlassHandle klass, constantPoolHandle cpool, Array<Method*>* methods, TRAPS);
   1.163  
   1.164    // Second pass, not gated by is_rewritten flag
   1.165    static void relocate_and_link(instanceKlassHandle klass, TRAPS);
   1.166    // JSR292 version to call with it's own methods.
   1.167    static void relocate_and_link(instanceKlassHandle klass,
   1.168 -                                objArrayHandle methods, TRAPS);
   1.169 +                                Array<Method*>* methods, TRAPS);
   1.170  
   1.171  };
   1.172  

mercurial