hotspot/src/share/vm/interpreter/rewriter.cpp
changeset 38031 e0b822facc03
parent 36819 bca375d368ed
child 39421 a9652c919db8
equal deleted inserted replaced
38030:93f24e7b3c43 38031:e0b822facc03
     1 /*
     1 /*
     2  * Copyright (c) 1998, 2015, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 1998, 2016, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.
     7  * published by the Free Software Foundation.
    63   }
    63   }
    64 
    64 
    65   // Record limits of resolved reference map for constant pool cache indices
    65   // Record limits of resolved reference map for constant pool cache indices
    66   record_map_limits();
    66   record_map_limits();
    67 
    67 
    68   guarantee((int)_cp_cache_map.length()-1 <= (int)((u2)-1),
    68   guarantee((int) _cp_cache_map.length() - 1 <= (int) ((u2)-1),
    69             "all cp cache indexes fit in a u2");
    69             "all cp cache indexes fit in a u2");
    70 
    70 
    71   if (saw_mh_symbol)
    71   if (saw_mh_symbol) {
    72     _method_handle_invokers.initialize(length, (int)0);
    72     _method_handle_invokers.at_grow(length, 0);
       
    73   }
    73 }
    74 }
    74 
    75 
    75 // Unrewrite the bytecodes if an error occurs.
    76 // Unrewrite the bytecodes if an error occurs.
    76 void Rewriter::restore_bytecodes() {
    77 void Rewriter::restore_bytecodes() {
    77   int len = _methods->length();
    78   int len = _methods->length();
   191         // allow invokespecial as an alias, although it would be very odd:
   192         // allow invokespecial as an alias, although it would be very odd:
   192         (*opc) == (u1)Bytecodes::_invokespecial) {
   193         (*opc) == (u1)Bytecodes::_invokespecial) {
   193       assert(_pool->tag_at(cp_index).is_method(), "wrong index");
   194       assert(_pool->tag_at(cp_index).is_method(), "wrong index");
   194       // Determine whether this is a signature-polymorphic method.
   195       // Determine whether this is a signature-polymorphic method.
   195       if (cp_index >= _method_handle_invokers.length())  return;
   196       if (cp_index >= _method_handle_invokers.length())  return;
   196       int status = _method_handle_invokers[cp_index];
   197       int status = _method_handle_invokers.at(cp_index);
   197       assert(status >= -1 && status <= 1, "oob tri-state");
   198       assert(status >= -1 && status <= 1, "oob tri-state");
   198       if (status == 0) {
   199       if (status == 0) {
   199         if (_pool->klass_ref_at_noresolve(cp_index) == vmSymbols::java_lang_invoke_MethodHandle() &&
   200         if (_pool->klass_ref_at_noresolve(cp_index) == vmSymbols::java_lang_invoke_MethodHandle() &&
   200             MethodHandles::is_signature_polymorphic_name(SystemDictionary::MethodHandle_klass(),
   201             MethodHandles::is_signature_polymorphic_name(SystemDictionary::MethodHandle_klass(),
   201                                                          _pool->name_ref_at(cp_index))) {
   202                                                          _pool->name_ref_at(cp_index))) {
   209           add_invokedynamic_resolved_references_entries(cp_index, cache_index);
   210           add_invokedynamic_resolved_references_entries(cp_index, cache_index);
   210           status = +1;
   211           status = +1;
   211         } else {
   212         } else {
   212           status = -1;
   213           status = -1;
   213         }
   214         }
   214         _method_handle_invokers[cp_index] = status;
   215         _method_handle_invokers.at(cp_index) = status;
   215       }
   216       }
   216       // We use a special internal bytecode for such methods (if non-static).
   217       // We use a special internal bytecode for such methods (if non-static).
   217       // The basic reason for this is that such methods need an extra "appendix" argument
   218       // The basic reason for this is that such methods need an extra "appendix" argument
   218       // to transmit the call site's intended call type.
   219       // to transmit the call site's intended call type.
   219       if (status > 0) {
   220       if (status > 0) {
   285 
   286 
   286       // invokedynamic resolved references map also points to cp cache and must
   287       // invokedynamic resolved references map also points to cp cache and must
   287       // add delta to each.
   288       // add delta to each.
   288       int resolved_index = _patch_invokedynamic_refs->at(i);
   289       int resolved_index = _patch_invokedynamic_refs->at(i);
   289       for (int entry = 0; entry < ConstantPoolCacheEntry::_indy_resolved_references_entries; entry++) {
   290       for (int entry = 0; entry < ConstantPoolCacheEntry::_indy_resolved_references_entries; entry++) {
   290         assert(_invokedynamic_references_map[resolved_index+entry] == cache_index,
   291         assert(_invokedynamic_references_map.at(resolved_index + entry) == cache_index,
   291              "should be the same index");
   292              "should be the same index");
   292         _invokedynamic_references_map.at_put(resolved_index+entry,
   293         _invokedynamic_references_map.at_put(resolved_index+entry,
   293                                              cache_index + delta);
   294                                              cache_index + delta);
   294       }
   295       }
   295     }
   296     }
   518 }
   519 }
   519 
   520 
   520 Rewriter::Rewriter(instanceKlassHandle klass, const constantPoolHandle& cpool, Array<Method*>* methods, TRAPS)
   521 Rewriter::Rewriter(instanceKlassHandle klass, const constantPoolHandle& cpool, Array<Method*>* methods, TRAPS)
   521   : _klass(klass),
   522   : _klass(klass),
   522     _pool(cpool),
   523     _pool(cpool),
   523     _methods(methods)
   524     _methods(methods),
       
   525     _cp_map(cpool->length()),
       
   526     _cp_cache_map(cpool->length() / 2),
       
   527     _reference_map(cpool->length()),
       
   528     _resolved_references_map(cpool->length() / 2),
       
   529     _invokedynamic_references_map(cpool->length() / 2),
       
   530     _method_handle_invokers(cpool->length()),
       
   531     _invokedynamic_cp_cache_map(cpool->length() / 4)
   524 {
   532 {
   525 
   533 
   526   // Rewrite bytecodes - exception here exits.
   534   // Rewrite bytecodes - exception here exits.
   527   rewrite_bytecodes(CHECK);
   535   rewrite_bytecodes(CHECK);
   528 
   536