< prev index next >

src/share/vm/interpreter/bytecodes.cpp

Print this page


   1 /*
   2  * Copyright (c) 1997, 2015, 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  *


  52 }
  53 #endif
  54 
  55 bool Bytecodes::check_must_rewrite(Bytecodes::Code code) {
  56   assert(can_rewrite(code), "post-check only");
  57 
  58   // Some codes are conditionally rewriting.  Look closely at them.
  59   switch (code) {
  60   case Bytecodes::_aload_0:
  61     // Even if RewriteFrequentPairs is turned on,
  62     // the _aload_0 code might delay its rewrite until
  63     // a following _getfield rewrites itself.
  64     return false;
  65 
  66   case Bytecodes::_lookupswitch:
  67     return false;  // the rewrite is not done by the interpreter
  68 
  69   case Bytecodes::_new:
  70     // (Could actually look at the class here, but the profit would be small.)
  71     return false;  // the rewrite is not always done
  72   }
  73 

  74   // No other special cases.
  75   return true;

  76 }
  77 
  78 Bytecodes::Code Bytecodes::code_at(Method* method, int bci) {
  79   return code_at(method, method->bcp_from(bci));
  80 }
  81 
  82 Bytecodes::Code Bytecodes::non_breakpoint_code_at(const Method* method, address bcp) {
  83   assert(method != NULL, "must have the method for breakpoint conversion");
  84   assert(method->contains(bcp), "must be valid bcp in method");
  85   return method->orig_bytecode_at(method->bci_from(bcp));
  86 }
  87 
  88 int Bytecodes::special_length_at(Bytecodes::Code code, address bcp, address end) {
  89   switch (code) {
  90   case _wide:
  91     if (end != NULL && bcp + 1 >= end) {
  92       return -1; // don't read past end of code buffer
  93     }
  94     return wide_length_for(cast(*(bcp + 1)));
  95   case _tableswitch:


 101       jlong hi = (jint)Bytes::get_Java_u4(aligned_bcp + 2*jintSize);
 102       jlong len = (aligned_bcp - bcp) + (3 + hi - lo + 1)*jintSize;
 103       // only return len if it can be represented as a positive int;
 104       // return -1 otherwise
 105       return (len > 0 && len == (int)len) ? len : -1;
 106     }
 107 
 108   case _lookupswitch:      // fall through
 109   case _fast_binaryswitch: // fall through
 110   case _fast_linearswitch:
 111     { address aligned_bcp = (address)round_to((intptr_t)bcp + 1, jintSize);
 112       if (end != NULL && aligned_bcp + 2*jintSize >= end) {
 113         return -1; // don't read past end of code buffer
 114       }
 115       jlong npairs = (jint)Bytes::get_Java_u4(aligned_bcp + jintSize);
 116       jlong len = (aligned_bcp - bcp) + (2 + 2*npairs)*jintSize;
 117       // only return len if it can be represented as a positive int;
 118       // return -1 otherwise
 119       return (len > 0 && len == (int)len) ? len : -1;
 120     }
 121   }
 122   // Note: Length functions must return <=0 for invalid bytecodes.
 123   return 0;

 124 }
 125 
 126 // At a breakpoint instruction, this returns the breakpoint's length,
 127 // otherwise, it's the same as special_length_at().  This is used by
 128 // the RawByteCodeStream, which wants to see the actual bytecode
 129 // values (including breakpoint).  RawByteCodeStream is used by the
 130 // verifier when reading in bytecode to verify.  Other mechanisms that
 131 // run at runtime (such as generateOopMaps) need to iterate over the code
 132 // and don't expect to see breakpoints: they want to see the instruction
 133 // which was replaced so that they can get the correct length and find
 134 // the next bytecode.
 135 //
 136 // 'end' indicates the end of the code buffer, which we should not try to read
 137 // past.
 138 int Bytecodes::raw_special_length_at(address bcp, address end) {
 139   Code code = code_or_bp_at(bcp);
 140   if (code == _breakpoint) {
 141     return 1;
 142   } else {
 143     return special_length_at(code, bcp, end);


   1 /*
   2  * Copyright (c) 1997, 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  *


  52 }
  53 #endif
  54 
  55 bool Bytecodes::check_must_rewrite(Bytecodes::Code code) {
  56   assert(can_rewrite(code), "post-check only");
  57 
  58   // Some codes are conditionally rewriting.  Look closely at them.
  59   switch (code) {
  60   case Bytecodes::_aload_0:
  61     // Even if RewriteFrequentPairs is turned on,
  62     // the _aload_0 code might delay its rewrite until
  63     // a following _getfield rewrites itself.
  64     return false;
  65 
  66   case Bytecodes::_lookupswitch:
  67     return false;  // the rewrite is not done by the interpreter
  68 
  69   case Bytecodes::_new:
  70     // (Could actually look at the class here, but the profit would be small.)
  71     return false;  // the rewrite is not always done

  72 
  73   default:
  74     // No other special cases.
  75     return true;
  76   }
  77 }
  78 
  79 Bytecodes::Code Bytecodes::code_at(Method* method, int bci) {
  80   return code_at(method, method->bcp_from(bci));
  81 }
  82 
  83 Bytecodes::Code Bytecodes::non_breakpoint_code_at(const Method* method, address bcp) {
  84   assert(method != NULL, "must have the method for breakpoint conversion");
  85   assert(method->contains(bcp), "must be valid bcp in method");
  86   return method->orig_bytecode_at(method->bci_from(bcp));
  87 }
  88 
  89 int Bytecodes::special_length_at(Bytecodes::Code code, address bcp, address end) {
  90   switch (code) {
  91   case _wide:
  92     if (end != NULL && bcp + 1 >= end) {
  93       return -1; // don't read past end of code buffer
  94     }
  95     return wide_length_for(cast(*(bcp + 1)));
  96   case _tableswitch:


 102       jlong hi = (jint)Bytes::get_Java_u4(aligned_bcp + 2*jintSize);
 103       jlong len = (aligned_bcp - bcp) + (3 + hi - lo + 1)*jintSize;
 104       // only return len if it can be represented as a positive int;
 105       // return -1 otherwise
 106       return (len > 0 && len == (int)len) ? len : -1;
 107     }
 108 
 109   case _lookupswitch:      // fall through
 110   case _fast_binaryswitch: // fall through
 111   case _fast_linearswitch:
 112     { address aligned_bcp = (address)round_to((intptr_t)bcp + 1, jintSize);
 113       if (end != NULL && aligned_bcp + 2*jintSize >= end) {
 114         return -1; // don't read past end of code buffer
 115       }
 116       jlong npairs = (jint)Bytes::get_Java_u4(aligned_bcp + jintSize);
 117       jlong len = (aligned_bcp - bcp) + (2 + 2*npairs)*jintSize;
 118       // only return len if it can be represented as a positive int;
 119       // return -1 otherwise
 120       return (len > 0 && len == (int)len) ? len : -1;
 121     }
 122   default:
 123     // Note: Length functions must return <=0 for invalid bytecodes.
 124     return 0;
 125   }
 126 }
 127 
 128 // At a breakpoint instruction, this returns the breakpoint's length,
 129 // otherwise, it's the same as special_length_at().  This is used by
 130 // the RawByteCodeStream, which wants to see the actual bytecode
 131 // values (including breakpoint).  RawByteCodeStream is used by the
 132 // verifier when reading in bytecode to verify.  Other mechanisms that
 133 // run at runtime (such as generateOopMaps) need to iterate over the code
 134 // and don't expect to see breakpoints: they want to see the instruction
 135 // which was replaced so that they can get the correct length and find
 136 // the next bytecode.
 137 //
 138 // 'end' indicates the end of the code buffer, which we should not try to read
 139 // past.
 140 int Bytecodes::raw_special_length_at(address bcp, address end) {
 141   Code code = code_or_bp_at(bcp);
 142   if (code == _breakpoint) {
 143     return 1;
 144   } else {
 145     return special_length_at(code, bcp, end);


< prev index next >