< prev index next >

src/hotspot/share/interpreter/rewriter.cpp

Print this page
   1 /*
   2  * Copyright (c) 1998, 2017, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   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
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 #include "precompiled.hpp"
  26 #include "gc/shared/gcLocker.hpp"
  27 #include "interpreter/bytecodes.hpp"
  28 #include "interpreter/interpreter.hpp"
  29 #include "interpreter/rewriter.hpp"
  30 #include "memory/metadataFactory.hpp"
  31 #include "memory/metaspaceShared.hpp"
  32 #include "memory/resourceArea.hpp"
  33 #include "oops/generateOopMap.hpp"
  34 #include "prims/methodHandles.hpp"
  35 
  36 // Computes a CPC map (new_index -> original_index) for constant pool entries
  37 // that are referred to by the interpreter at runtime via the constant pool cache.
  38 // Also computes a CP map (original_index -> new_index).
  39 // Marks entries in CP which require additional processing.
  40 void Rewriter::compute_index_maps() {
  41   const int length  = _pool->length();
  42   init_maps(length);
  43   bool saw_mh_symbol = false;
  44   for (int i = 0; i < length; i++) {
  45     int tag = _pool->tag_at(i).value();
  46     switch (tag) {
  47       case JVM_CONSTANT_InterfaceMethodref:
  48       case JVM_CONSTANT_Fieldref          : // fall through
  49       case JVM_CONSTANT_Methodref         : // fall through
  50         add_cp_cache_entry(i);
  51         break;


 539     Method* method = _methods->at(i);
 540     scan_method(method, false, &invokespecial_error);
 541     if (invokespecial_error) {
 542       // If you get an error here, there is no reversing bytecodes
 543       // This exception is stored for this class and no further attempt is
 544       // made at verifying or rewriting.
 545       THROW_MSG(vmSymbols::java_lang_InternalError(),
 546                 "This classfile overflows invokespecial for interfaces "
 547                 "and cannot be loaded");
 548       return;
 549      }
 550   }
 551 
 552   // May have to fix invokedynamic bytecodes if invokestatic/InterfaceMethodref
 553   // entries had to be added.
 554   patch_invokedynamic_bytecodes();
 555 }
 556 
 557 void Rewriter::rewrite(InstanceKlass* klass, TRAPS) {
 558   if (!DumpSharedSpaces) {
 559     assert(!MetaspaceShared::is_in_shared_space(klass), "archive methods must not be rewritten at run time");
 560   }
 561   ResourceMark rm(THREAD);
 562   Rewriter     rw(klass, klass->constants(), klass->methods(), CHECK);
 563   // (That's all, folks.)
 564 }
 565 
 566 Rewriter::Rewriter(InstanceKlass* klass, const constantPoolHandle& cpool, Array<Method*>* methods, TRAPS)
 567   : _klass(klass),
 568     _pool(cpool),
 569     _methods(methods),
 570     _cp_map(cpool->length()),
 571     _cp_cache_map(cpool->length() / 2),
 572     _reference_map(cpool->length()),
 573     _resolved_references_map(cpool->length() / 2),
 574     _invokedynamic_references_map(cpool->length() / 2),
 575     _method_handle_invokers(cpool->length()),
 576     _invokedynamic_cp_cache_map(cpool->length() / 4)
 577 {
 578 
 579   // Rewrite bytecodes - exception here exits.


   1 /*
   2  * Copyright (c) 1998, 2018, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   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
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 #include "precompiled.hpp"
  26 #include "gc/shared/gcLocker.hpp"
  27 #include "interpreter/bytecodes.hpp"
  28 #include "interpreter/interpreter.hpp"
  29 #include "interpreter/rewriter.hpp"
  30 #include "memory/metadataFactory.hpp"

  31 #include "memory/resourceArea.hpp"
  32 #include "oops/generateOopMap.hpp"
  33 #include "prims/methodHandles.hpp"
  34 
  35 // Computes a CPC map (new_index -> original_index) for constant pool entries
  36 // that are referred to by the interpreter at runtime via the constant pool cache.
  37 // Also computes a CP map (original_index -> new_index).
  38 // Marks entries in CP which require additional processing.
  39 void Rewriter::compute_index_maps() {
  40   const int length  = _pool->length();
  41   init_maps(length);
  42   bool saw_mh_symbol = false;
  43   for (int i = 0; i < length; i++) {
  44     int tag = _pool->tag_at(i).value();
  45     switch (tag) {
  46       case JVM_CONSTANT_InterfaceMethodref:
  47       case JVM_CONSTANT_Fieldref          : // fall through
  48       case JVM_CONSTANT_Methodref         : // fall through
  49         add_cp_cache_entry(i);
  50         break;


 538     Method* method = _methods->at(i);
 539     scan_method(method, false, &invokespecial_error);
 540     if (invokespecial_error) {
 541       // If you get an error here, there is no reversing bytecodes
 542       // This exception is stored for this class and no further attempt is
 543       // made at verifying or rewriting.
 544       THROW_MSG(vmSymbols::java_lang_InternalError(),
 545                 "This classfile overflows invokespecial for interfaces "
 546                 "and cannot be loaded");
 547       return;
 548      }
 549   }
 550 
 551   // May have to fix invokedynamic bytecodes if invokestatic/InterfaceMethodref
 552   // entries had to be added.
 553   patch_invokedynamic_bytecodes();
 554 }
 555 
 556 void Rewriter::rewrite(InstanceKlass* klass, TRAPS) {
 557   if (!DumpSharedSpaces) {
 558     assert(!klass->is_shared(), "archive methods must not be rewritten at run time");
 559   }
 560   ResourceMark rm(THREAD);
 561   Rewriter     rw(klass, klass->constants(), klass->methods(), CHECK);
 562   // (That's all, folks.)
 563 }
 564 
 565 Rewriter::Rewriter(InstanceKlass* klass, const constantPoolHandle& cpool, Array<Method*>* methods, TRAPS)
 566   : _klass(klass),
 567     _pool(cpool),
 568     _methods(methods),
 569     _cp_map(cpool->length()),
 570     _cp_cache_map(cpool->length() / 2),
 571     _reference_map(cpool->length()),
 572     _resolved_references_map(cpool->length() / 2),
 573     _invokedynamic_references_map(cpool->length() / 2),
 574     _method_handle_invokers(cpool->length()),
 575     _invokedynamic_cp_cache_map(cpool->length() / 4)
 576 {
 577 
 578   // Rewrite bytecodes - exception here exits.


< prev index next >