/* * Copyright (c) 1997, 2022, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. *
*/
// Some codes are conditionally rewriting. Look closely at them. switch (code) { case Bytecodes::_aload_0: // Even if RewriteFrequentPairs is turned on, // the _aload_0 code might delay its rewrite until // a following _getfield rewrites itself. returnfalse;
case Bytecodes::_lookupswitch: returnfalse; // the rewrite is not done by the interpreter
case Bytecodes::_new: // (Could actually look at the class here, but the profit would be small.) returnfalse; // the rewrite is not always done
default: // No other special cases. returntrue;
}
}
Bytecodes::Code Bytecodes::code_at(Method* method, int bci) { return code_at(method, method->bcp_from(bci));
}
Bytecodes::Code Bytecodes::non_breakpoint_code_at(const Method* method, address bcp) {
assert(method != NULL, "must have the method for breakpoint conversion");
assert(method->contains(bcp), "must be valid bcp in method"); return method->orig_bytecode_at(method->bci_from(bcp));
}
int Bytecodes::special_length_at(Bytecodes::Code code, address bcp, address end) { switch (code) { case _wide: if (end != NULL && bcp + 1 >= end) { return -1; // don't read past end of code buffer
} return wide_length_for(cast(*(bcp + 1))); case _tableswitch:
{ address aligned_bcp = align_up(bcp + 1, jintSize); if (end != NULL && aligned_bcp + 3*jintSize >= end) { return -1; // don't read past end of code buffer
}
jlong lo = (jint)Bytes::get_Java_u4(aligned_bcp + 1*jintSize);
jlong hi = (jint)Bytes::get_Java_u4(aligned_bcp + 2*jintSize);
jlong len = (aligned_bcp - bcp) + (3 + hi - lo + 1)*jintSize; // only return len if it can be represented as a positive int; // return -1 otherwise return (len > 0 && len == (int)len) ? len : -1;
}
case _lookupswitch: // fall through case _fast_binaryswitch: // fall through case _fast_linearswitch:
{ address aligned_bcp = align_up(bcp + 1, jintSize); if (end != NULL && aligned_bcp + 2*jintSize >= end) { return -1; // don't read past end of code buffer
}
jlong npairs = (jint)Bytes::get_Java_u4(aligned_bcp + jintSize);
jlong len = (aligned_bcp - bcp) + (2 + 2*npairs)*jintSize; // only return len if it can be represented as a positive int; // return -1 otherwise return (len > 0 && len == (int)len) ? len : -1;
} default: // Note: Length functions must return <=0 for invalid bytecodes. return 0;
}
}
// At a breakpoint instruction, this returns the breakpoint's length, // otherwise, it's the same as special_length_at(). This is used by // the RawByteCodeStream, which wants to see the actual bytecode // values (including breakpoint). RawByteCodeStream is used by the // verifier when reading in bytecode to verify. Other mechanisms that // run at runtime (such as generateOopMaps) need to iterate over the code // and don't expect to see breakpoints: they want to see the instruction // which was replaced so that they can get the correct length and find // the next bytecode. // // 'end' indicates the end of the code buffer, which we should not try to read // past. int Bytecodes::raw_special_length_at(address bcp, address end) {
Code code = code_or_bp_at(bcp); if (code == _breakpoint) { return 1;
} else { return special_length_at(code, bcp, end);
}
}
void Bytecodes::def(Code code, constchar* name, constchar* format, constchar* wide_format, BasicType result_type, int depth, bool can_trap) {
def(code, name, format, wide_format, result_type, depth, can_trap, code);
}
void Bytecodes::def(Code code, constchar* name, constchar* format, constchar* wide_format, BasicType result_type, int depth, bool can_trap, Code java_code) {
assert(wide_format == NULL || format != NULL, "short form must exist if there's a wide form"); int len = (format != NULL ? (int) strlen(format) : 0); int wlen = (wide_format != NULL ? (int) strlen(wide_format) : 0);
_name [code] = name;
_result_type [code] = result_type;
_depth [code] = depth;
_lengths [code] = (wlen << 4) | (len & 0xF);
_java_code [code] = java_code; int bc_flags = 0; if (can_trap) bc_flags |= _bc_can_trap; if (java_code != code) bc_flags |= _bc_can_rewrite;
_flags[(u1)code+0*(1<<BitsPerByte)] = compute_flags(format, bc_flags);
_flags[(u1)code+1*(1<<BitsPerByte)] = compute_flags(wide_format, bc_flags);
assert(is_defined(code) == (format != NULL), "");
assert(wide_is_defined(code) == (wide_format != NULL), "");
assert(length_for(code) == len, "");
assert(wide_length_for(code) == wlen, "");
}
// Format strings interpretation: // // b: bytecode // c: signed constant, Java byte-ordering // i: unsigned local index, Java byte-ordering (I = native byte ordering) // j: unsigned CP cache index, Java byte-ordering (J = native byte ordering) // k: unsigned CP index, Java byte-ordering // o: branch offset, Java byte-ordering // _: unused/ignored // w: wide bytecode // // Note: The format strings are used for 2 purposes: // 1. to specify the length of the bytecode // (= number of characters in format string) // 2. to derive bytecode format flags (_fmt_has_k, etc.) // // Note: For bytecodes with variable length, the format string is the empty string.
int Bytecodes::compute_flags(constchar* format, int more_flags) { if (format == NULL) return 0; // not even more_flags int flags = more_flags; constchar* fp = format; switch (*fp) { case'\0':
flags |= _fmt_not_simple; // but variable break; case'b':
flags |= _fmt_not_variable; // but simple
++fp; // skip 'b' break; case'w':
flags |= _fmt_not_variable | _fmt_not_simple;
++fp; // skip 'w'
guarantee(*fp == 'b', "wide format must start with 'wb'");
++fp; // skip 'b' break;
}
int has_nbo = 0, has_jbo = 0, has_size = 0; for (;;) { int this_flag = 0; char fc = *fp++; switch (fc) { case'\0': // end of string
assert(flags == (jchar)flags, "change _format_flags"); return flags;
// uppercase versions mark native byte order (from Rewriter) // actually, only the 'J' case happens currently case'J': this_flag = _fmt_has_j; has_nbo = 1; break; case'K': this_flag = _fmt_has_k; has_nbo = 1; break; case'I': this_flag = _fmt_has_i; has_nbo = 1; break; case'C': this_flag = _fmt_has_c; has_nbo = 1; break; case'O': this_flag = _fmt_has_o; has_nbo = 1; break; default: guarantee(false, "bad char in format");
}
flags |= this_flag;
guarantee(!(has_jbo && has_nbo), "mixed byte orders in format"); if (has_nbo)
flags |= _fmt_has_nbo;
int this_size = 1; if (*fp == fc) { // advance beyond run of the same characters
this_size = 2; while (*++fp == fc) this_size++; switch (this_size) { case 2: flags |= _fmt_has_u2; break; case 4: flags |= _fmt_has_u4; break; default: guarantee(false, "bad rep count in format");
}
}
guarantee(has_size == 0 || // no field yet
this_size == has_size || // same size
this_size < has_size && *fp == '\0', // last field can be short "mixed field sizes in format");
has_size = this_size;
}
}
void Bytecodes::initialize() { if (_is_initialized) return;
assert(number_of_codes <= 256, "too many bytecodes");
// initialize bytecode tables - didn't use static array initializers // (such as {}) so we can do additional consistency checks and init- // code is independent of actual bytecode numbering. // // Note 1: NULL for the format string means the bytecode doesn't exist // in that form. // // Note 2: The result type is T_ILLEGAL for bytecodes where the top of stack // type after execution is not only determined by the bytecode itself.
// compare can_trap information for each bytecode with the // can_trap information for the corresponding base bytecode // (if a rewritten bytecode can trap, so must the base bytecode) #ifdef ASSERT
{ for (int i = 0; i < number_of_codes; i++) { if (is_defined(i)) {
Code code = cast(i);
Code java = java_code(code); if (can_trap(code) && !can_trap(java))
fatal("%s can trap => %s can trap, too", name(code), name(java));
}
}
} #endif
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.