8140594: Various minor code improvements (compiler)

Various minor code improvements (compiler)

Reviewed-by: thartmann, kvn
This commit is contained in:
Goetz Lindenmaier 2016-05-03 12:23:06 +02:00
parent 96c4dc3210
commit 1e4b00b1dc
19 changed files with 77 additions and 56 deletions

View File

@ -1913,9 +1913,10 @@ static bool _print_ascii_file(const char* filename, outputStream* st) {
return false; return false;
} }
char buf[32]; char buf[33];
int bytes; int bytes;
while ((bytes = ::read(fd, buf, sizeof(buf))) > 0) { buf[32] = '\0';
while ((bytes = ::read(fd, buf, sizeof(buf)-1)) > 0) {
st->print_raw(buf, bytes); st->print_raw(buf, bytes);
} }
@ -6033,8 +6034,8 @@ int os::get_core_path(char* buffer, size_t bufferSize) {
if (core_pattern[0] == '|') { if (core_pattern[0] == '|') {
written = jio_snprintf(buffer, bufferSize, written = jio_snprintf(buffer, bufferSize,
"\"%s\" (or dumping to %s/core.%d)", "\"%s\" (or dumping to %s/core.%d)",
&core_pattern[1], p, current_process_id()); &core_pattern[1], p, current_process_id());
} else { } else {
written = jio_snprintf(buffer, bufferSize, "%s/%s", p, core_pattern); written = jio_snprintf(buffer, bufferSize, "%s/%s", p, core_pattern);
} }
@ -6067,20 +6068,20 @@ bool os::start_debugging(char *buf, int buflen) {
char *p = &buf[len]; char *p = &buf[len];
jio_snprintf(p, buflen-len, jio_snprintf(p, buflen-len,
"\n\n" "\n\n"
"Do you want to debug the problem?\n\n" "Do you want to debug the problem?\n\n"
"To debug, run 'gdb /proc/%d/exe %d'; then switch to thread " UINTX_FORMAT " (" INTPTR_FORMAT ")\n" "To debug, run 'gdb /proc/%d/exe %d'; then switch to thread " UINTX_FORMAT " (" INTPTR_FORMAT ")\n"
"Enter 'yes' to launch gdb automatically (PATH must include gdb)\n" "Enter 'yes' to launch gdb automatically (PATH must include gdb)\n"
"Otherwise, press RETURN to abort...", "Otherwise, press RETURN to abort...",
os::current_process_id(), os::current_process_id(), os::current_process_id(), os::current_process_id(),
os::current_thread_id(), os::current_thread_id()); os::current_thread_id(), os::current_thread_id());
bool yes = os::message_box("Unexpected Error", buf); bool yes = os::message_box("Unexpected Error", buf);
if (yes) { if (yes) {
// yes, user asked VM to launch debugger // yes, user asked VM to launch debugger
jio_snprintf(buf, sizeof(buf), "gdb /proc/%d/exe %d", jio_snprintf(buf, sizeof(char)*buflen, "gdb /proc/%d/exe %d",
os::current_process_id(), os::current_process_id()); os::current_process_id(), os::current_process_id());
os::fork_and_exec(buf); os::fork_and_exec(buf);
yes = false; yes = false;

View File

@ -823,7 +823,7 @@ void os::print_context(outputStream *st, const void *context) {
intptr_t *sp = (intptr_t *)os::Linux::ucontext_get_sp(uc); intptr_t *sp = (intptr_t *)os::Linux::ucontext_get_sp(uc);
st->print_cr("Top of Stack: (sp=" PTR_FORMAT ")", p2i(sp)); st->print_cr("Top of Stack: (sp=" PTR_FORMAT ")", p2i(sp));
print_hex_dump(st, (address)sp, (address)(sp + 8*sizeof(intptr_t)), sizeof(intptr_t)); print_hex_dump(st, (address)sp, (address)(sp + 8), sizeof(intptr_t));
st->cr(); st->cr();
// Note: it may be unsafe to inspect memory near pc. For example, pc may // Note: it may be unsafe to inspect memory near pc. For example, pc may

View File

@ -1499,7 +1499,8 @@ void MachNodeForm::output(FILE *fp) {
// twice, we need to check that the operands are pointer-eequivalent in // twice, we need to check that the operands are pointer-eequivalent in
// the DFA during the labeling process. // the DFA during the labeling process.
Predicate *InstructForm::build_predicate() { Predicate *InstructForm::build_predicate() {
char buf[1024], *s=buf; const int buflen = 1024;
char buf[buflen], *s=buf;
Dict names(cmpstr,hashstr,Form::arena); // Map Names to counts Dict names(cmpstr,hashstr,Form::arena); // Map Names to counts
MatchNode *mnode = MatchNode *mnode =
@ -1508,12 +1509,12 @@ Predicate *InstructForm::build_predicate() {
uint first = 1; uint first = 1;
// Start with the predicate supplied in the .ad file. // Start with the predicate supplied in the .ad file.
if( _predicate ) { if (_predicate) {
if( first ) first=0; if (first) first = 0;
strcpy(s,"("); s += strlen(s); strcpy(s, "("); s += strlen(s);
strcpy(s,_predicate->_pred); strncpy(s, _predicate->_pred, buflen - strlen(s) - 1);
s += strlen(s); s += strlen(s);
strcpy(s,")"); s += strlen(s); strcpy(s, ")"); s += strlen(s);
} }
for( DictI i(&names); i.test(); ++i ) { for( DictI i(&names); i.test(); ++i ) {
uintptr_t cnt = (uintptr_t)i._value; uintptr_t cnt = (uintptr_t)i._value;

View File

@ -5521,7 +5521,8 @@ int LinearScanWalker::find_locked_double_reg(int reg_needed_until, int interval_
} }
} }
if (_block_pos[max_reg] <= interval_to || _block_pos[max_reg + 1] <= interval_to) { if (max_reg != any_reg &&
(_block_pos[max_reg] <= interval_to || _block_pos[max_reg + 1] <= interval_to)) {
*need_split = true; *need_split = true;
} }
@ -6497,8 +6498,9 @@ void LinearScanStatistic::print(const char* title) {
if (_counters_sum[i] > 0 || _counters_max[i] >= 0) { if (_counters_sum[i] > 0 || _counters_max[i] >= 0) {
tty->print("%25s: %8d", counter_name(i), _counters_sum[i]); tty->print("%25s: %8d", counter_name(i), _counters_sum[i]);
if (base_counter(i) != invalid_counter) { LinearScanStatistic::Counter cntr = base_counter(i);
tty->print(" (%5.1f%%) ", _counters_sum[i] * 100.0 / _counters_sum[base_counter(i)]); if (cntr != invalid_counter) {
tty->print(" (%5.1f%%) ", _counters_sum[i] * 100.0 / _counters_sum[cntr]);
} else { } else {
tty->print(" "); tty->print(" ");
} }

View File

@ -372,7 +372,7 @@ static const char *flagnames[] = {
void ciBlock::dump() { void ciBlock::dump() {
tty->print(" [%d .. %d), {", _start_bci, _limit_bci); tty->print(" [%d .. %d), {", _start_bci, _limit_bci);
for (int i = 0; i < 8; i++) { for (int i = 0; i < 7; i++) {
if ((_flags & (1 << i)) != 0) { if ((_flags & (1 << i)) != 0) {
tty->print(" %s", flagnames[i]); tty->print(" %s", flagnames[i]);
} }

View File

@ -1401,9 +1401,11 @@ class ClassFileParser::FieldAllocationCount : public ResourceObj {
FieldAllocationType update(bool is_static, BasicType type) { FieldAllocationType update(bool is_static, BasicType type) {
FieldAllocationType atype = basic_type_to_atype(is_static, type); FieldAllocationType atype = basic_type_to_atype(is_static, type);
// Make sure there is no overflow with injected fields. if (atype != BAD_ALLOCATION_TYPE) {
assert(count[atype] < 0xFFFF, "More than 65535 fields"); // Make sure there is no overflow with injected fields.
count[atype]++; assert(count[atype] < 0xFFFF, "More than 65535 fields");
count[atype]++;
}
return atype; return atype;
} }
}; };
@ -3335,8 +3337,9 @@ void ClassFileParser::parse_classfile_attributes(const ClassFileStream* const cf
} }
} else if (tag == vmSymbols::tag_bootstrap_methods() && } else if (tag == vmSymbols::tag_bootstrap_methods() &&
_major_version >= Verifier::INVOKEDYNAMIC_MAJOR_VERSION) { _major_version >= Verifier::INVOKEDYNAMIC_MAJOR_VERSION) {
if (parsed_bootstrap_methods_attribute) if (parsed_bootstrap_methods_attribute) {
classfile_parse_error("Multiple BootstrapMethods attributes in class file %s", CHECK); classfile_parse_error("Multiple BootstrapMethods attributes in class file %s", CHECK);
}
parsed_bootstrap_methods_attribute = true; parsed_bootstrap_methods_attribute = true;
parse_classfile_bootstrap_methods_attribute(cfs, cp, attribute_length, CHECK); parse_classfile_bootstrap_methods_attribute(cfs, cp, attribute_length, CHECK);
} else if (tag == vmSymbols::tag_runtime_visible_type_annotations()) { } else if (tag == vmSymbols::tag_runtime_visible_type_annotations()) {

View File

@ -305,11 +305,9 @@ u1* ClassPathZipEntry::open_versioned_entry(const char* name, jint* filesize, TR
} }
if (is_multi_ver) { if (is_multi_ver) {
int n;
char entry_name[JVM_MAXPATHLEN]; char entry_name[JVM_MAXPATHLEN];
if (version > 0) { if (version > 0) {
n = jio_snprintf(entry_name, sizeof(entry_name), "META-INF/versions/%d/%s", version, name); jio_snprintf(entry_name, sizeof(entry_name), "META-INF/versions/%d/%s", version, name);
entry_name[n] = '\0';
buffer = open_entry((const char*)entry_name, filesize, false, CHECK_NULL); buffer = open_entry((const char*)entry_name, filesize, false, CHECK_NULL);
if (buffer == NULL) { if (buffer == NULL) {
warning("Could not find %s in %s, try to find highest version instead", entry_name, _zip_name); warning("Could not find %s in %s, try to find highest version instead", entry_name, _zip_name);
@ -317,8 +315,7 @@ u1* ClassPathZipEntry::open_versioned_entry(const char* name, jint* filesize, TR
} }
if (buffer == NULL) { if (buffer == NULL) {
for (int i = cur_ver; i >= base_version; i--) { for (int i = cur_ver; i >= base_version; i--) {
n = jio_snprintf(entry_name, sizeof(entry_name), "META-INF/versions/%d/%s", i, name); jio_snprintf(entry_name, sizeof(entry_name), "META-INF/versions/%d/%s", i, name);
entry_name[n] = '\0';
buffer = open_entry((const char*)entry_name, filesize, false, CHECK_NULL); buffer = open_entry((const char*)entry_name, filesize, false, CHECK_NULL);
if (buffer != NULL) { if (buffer != NULL) {
break; break;

View File

@ -1160,10 +1160,10 @@ Klass* SystemDictionary::resolve_from_stream(Symbol* class_name,
while ((index = strchr(name, '/')) != NULL) { while ((index = strchr(name, '/')) != NULL) {
*index = '.'; // replace '/' with '.' in package name *index = '.'; // replace '/' with '.' in package name
} }
const char* fmt = "Prohibited package name: %s"; const char* msg_text = "Prohibited package name: ";
size_t len = strlen(fmt) + strlen(name); size_t len = strlen(msg_text) + strlen(name) + 1;
char* message = NEW_RESOURCE_ARRAY(char, len); char* message = NEW_RESOURCE_ARRAY(char, len);
jio_snprintf(message, len, fmt, name); jio_snprintf(message, len, "%s%s", msg_text, name);
Exceptions::_throw_msg(THREAD_AND_LOCATION, Exceptions::_throw_msg(THREAD_AND_LOCATION,
vmSymbols::java_lang_SecurityException(), message); vmSymbols::java_lang_SecurityException(), message);
} }

View File

@ -2392,10 +2392,9 @@ void CompileBroker::print_times(bool per_compiler, bool aggregate) {
// Debugging output for failure // Debugging output for failure
void CompileBroker::print_last_compile() { void CompileBroker::print_last_compile() {
if ( _last_compile_level != CompLevel_none && if (_last_compile_level != CompLevel_none &&
compiler(_last_compile_level) != NULL && compiler(_last_compile_level) != NULL &&
_last_method_compiled != NULL && _last_compile_type != no_compile) {
_last_compile_type != no_compile) {
if (_last_compile_type == osr_compile) { if (_last_compile_type == osr_compile) {
tty->print_cr("Last parse: [osr]%d+++(%d) %s", tty->print_cr("Last parse: [osr]%d+++(%d) %s",
_osr_compilation_id, _last_compile_level, _last_method_compiled); _osr_compilation_id, _last_compile_level, _last_method_compiled);

View File

@ -231,7 +231,8 @@ void CompileLog::finish_log_on_error(outputStream* file, char* buf, int buflen)
// Copy any remaining data inside a quote: // Copy any remaining data inside a quote:
bool saw_slop = false; bool saw_slop = false;
int end_cdata = 0; // state machine [0..2] watching for too many "]]" int end_cdata = 0; // state machine [0..2] watching for too many "]]"
while ((nr = read(partial_fd, buf, buflen)) > 0) { while ((nr = read(partial_fd, buf, buflen-1)) > 0) {
buf[buflen-1] = '\0';
if (!saw_slop) { if (!saw_slop) {
file->print_raw_cr("<fragment>"); file->print_raw_cr("<fragment>");
file->print_raw_cr("<![CDATA["); file->print_raw_cr("<![CDATA[");

View File

@ -99,7 +99,7 @@ bool Disassembler::load_library() {
const char* p = strrchr(buf, *os::file_separator()); const char* p = strrchr(buf, *os::file_separator());
if (p != NULL) lib_offset = p - base + 1; if (p != NULL) lib_offset = p - base + 1;
p = strstr(p ? p : base, "jvm"); p = strstr(p ? p : base, "jvm");
if (p != NULL) jvm_offset = p - base; if (p != NULL) jvm_offset = p - base;
} }
#endif #endif
// Find the disassembler shared library. // Find the disassembler shared library.
@ -113,13 +113,13 @@ bool Disassembler::load_library() {
strcpy(&buf[jvm_offset], hsdis_library_name); strcpy(&buf[jvm_offset], hsdis_library_name);
strcat(&buf[jvm_offset], os::dll_file_extension()); strcat(&buf[jvm_offset], os::dll_file_extension());
_library = os::dll_load(buf, ebuf, sizeof ebuf); _library = os::dll_load(buf, ebuf, sizeof ebuf);
if (_library == NULL) { if (_library == NULL && lib_offset >= 0) {
// 2. <home>/jre/lib/<arch>/<vm>/hsdis-<arch>.so // 2. <home>/jre/lib/<arch>/<vm>/hsdis-<arch>.so
strcpy(&buf[lib_offset], hsdis_library_name); strcpy(&buf[lib_offset], hsdis_library_name);
strcat(&buf[lib_offset], os::dll_file_extension()); strcat(&buf[lib_offset], os::dll_file_extension());
_library = os::dll_load(buf, ebuf, sizeof ebuf); _library = os::dll_load(buf, ebuf, sizeof ebuf);
} }
if (_library == NULL) { if (_library == NULL && lib_offset > 0) {
// 3. <home>/jre/lib/<arch>/hsdis-<arch>.so // 3. <home>/jre/lib/<arch>/hsdis-<arch>.so
buf[lib_offset - 1] = '\0'; buf[lib_offset - 1] = '\0';
const char* p = strrchr(buf, *os::file_separator()); const char* p = strrchr(buf, *os::file_separator());

View File

@ -104,12 +104,18 @@ void LogTagSet::vwrite(LogLevelType level, const char* fmt, va_list args) {
va_copy(saved_args, args); va_copy(saved_args, args);
size_t prefix_len = _write_prefix(buf, sizeof(buf)); size_t prefix_len = _write_prefix(buf, sizeof(buf));
// Check that string fits in buffer; resize buffer if necessary // Check that string fits in buffer; resize buffer if necessary
int ret = os::log_vsnprintf(buf + prefix_len, sizeof(buf) - prefix_len, fmt, args); int ret;
if (prefix_len < vwrite_buffer_size) {
ret = os::log_vsnprintf(buf + prefix_len, sizeof(buf) - prefix_len, fmt, args);
} else {
// Buffer too small. Just call printf to find out the length for realloc below.
ret = os::log_vsnprintf(buf, sizeof(buf), fmt, args);
}
assert(ret >= 0, "Log message buffer issue"); assert(ret >= 0, "Log message buffer issue");
if ((size_t)ret >= sizeof(buf)) { if ((size_t)ret >= sizeof(buf)) {
size_t newbuf_len = prefix_len + ret + 1; size_t newbuf_len = prefix_len + ret + 1;
char* newbuf = NEW_C_HEAP_ARRAY(char, newbuf_len, mtLogging); char* newbuf = NEW_C_HEAP_ARRAY(char, newbuf_len, mtLogging);
memcpy(newbuf, buf, prefix_len); prefix_len = _write_prefix(newbuf, newbuf_len);
ret = os::log_vsnprintf(newbuf + prefix_len, newbuf_len - prefix_len, fmt, saved_args); ret = os::log_vsnprintf(newbuf + prefix_len, newbuf_len - prefix_len, fmt, saved_args);
assert(ret >= 0, "Log message buffer issue"); assert(ret >= 0, "Log message buffer issue");
log(level, newbuf); log(level, newbuf);

View File

@ -80,7 +80,8 @@ static bool tag_array_is_zero_initialized(Array<u1>* tags) {
ConstantPool::ConstantPool(Array<u1>* tags) : ConstantPool::ConstantPool(Array<u1>* tags) :
_tags(tags), _tags(tags),
_length(tags->length()) { _length(tags->length()),
_flags(0) {
assert(_tags != NULL, "invariant"); assert(_tags != NULL, "invariant");
assert(tags->length() == _length, "invariant"); assert(tags->length() == _length, "invariant");

View File

@ -1678,8 +1678,14 @@ void GenerateOopMap::ppdupswap(int poplen, const char *out) {
CellTypeState actual[5]; CellTypeState actual[5];
assert(poplen < 5, "this must be less than length of actual vector"); assert(poplen < 5, "this must be less than length of actual vector");
// pop all arguments // Pop all arguments.
for(int i = 0; i < poplen; i++) actual[i] = pop(); for (int i = 0; i < poplen; i++) {
actual[i] = pop();
}
// Field _state is uninitialized when calling push.
for (int i = poplen; i < 5; i++) {
actual[i] = CellTypeState::uninit;
}
// put them back // put them back
char push_ch = *out++; char push_ch = *out++;

View File

@ -1430,7 +1430,7 @@ void PhaseBlockLayout::find_edges() {
if (n->num_preds() != 1) break; if (n->num_preds() != 1) break;
i++; i++;
assert(n = _cfg.get_block(i), "expecting next block"); assert(n == _cfg.get_block(i), "expecting next block");
tr->append(n); tr->append(n);
uf->map(n->_pre_order, tr->id()); uf->map(n->_pre_order, tr->id());
traces[n->_pre_order] = NULL; traces[n->_pre_order] = NULL;

View File

@ -256,6 +256,7 @@ uint TailJumpNode::match_edge(uint idx) const {
JVMState::JVMState(ciMethod* method, JVMState* caller) : JVMState::JVMState(ciMethod* method, JVMState* caller) :
_method(method) { _method(method) {
assert(method != NULL, "must be valid call site"); assert(method != NULL, "must be valid call site");
_bci = InvocationEntryBci;
_reexecute = Reexecute_Undefined; _reexecute = Reexecute_Undefined;
debug_only(_bci = -99); // random garbage value debug_only(_bci = -99); // random garbage value
debug_only(_map = (SafePointNode*)-1); debug_only(_map = (SafePointNode*)-1);

View File

@ -1079,7 +1079,7 @@ bool GraphKit::compute_stack_effects(int& inputs, int& depth) {
case Bytecodes::_freturn: case Bytecodes::_freturn:
case Bytecodes::_dreturn: case Bytecodes::_dreturn:
case Bytecodes::_areturn: case Bytecodes::_areturn:
assert(rsize = -depth, ""); assert(rsize == -depth, "");
inputs = rsize; inputs = rsize;
break; break;

View File

@ -659,11 +659,14 @@ void Matcher::Fixup_Save_On_Entry( ) {
uint reth_edge_cnt = TypeFunc::Parms+1; uint reth_edge_cnt = TypeFunc::Parms+1;
RegMask *reth_rms = init_input_masks( reth_edge_cnt + soe_cnt, _return_addr_mask, c_frame_ptr_mask ); RegMask *reth_rms = init_input_masks( reth_edge_cnt + soe_cnt, _return_addr_mask, c_frame_ptr_mask );
// Rethrow takes exception oop only, but in the argument 0 slot. // Rethrow takes exception oop only, but in the argument 0 slot.
reth_rms[TypeFunc::Parms] = mreg2regmask[find_receiver(false)]; OptoReg::Name reg = find_receiver(false);
if (reg >= 0) {
reth_rms[TypeFunc::Parms] = mreg2regmask[reg];
#ifdef _LP64 #ifdef _LP64
// Need two slots for ptrs in 64-bit land // Need two slots for ptrs in 64-bit land
reth_rms[TypeFunc::Parms].Insert(OptoReg::add(OptoReg::Name(find_receiver(false)),1)); reth_rms[TypeFunc::Parms].Insert(OptoReg::add(OptoReg::Name(reg), 1));
#endif #endif
}
// Input RegMask array shared by all TailCalls // Input RegMask array shared by all TailCalls
uint tail_call_edge_cnt = TypeFunc::Parms+2; uint tail_call_edge_cnt = TypeFunc::Parms+2;

View File

@ -612,8 +612,8 @@ bool Relocator::relocate_code(int bci, int ilen, int delta) {
// In case we have shrunken a tableswitch/lookupswitch statement, we store the last // In case we have shrunken a tableswitch/lookupswitch statement, we store the last
// bytes that get overwritten. We have to copy the bytes after the change_jumps method // bytes that get overwritten. We have to copy the bytes after the change_jumps method
// has been called, since it is likely to update last offset in a tableswitch/lookupswitch // has been called, since it is likely to update last offset in a tableswitch/lookupswitch
if (delta < 0) { assert(delta >= -3, "We cannot overwrite more than 3 bytes.");
assert(delta>=-3, "we cannot overwrite more than 3 bytes"); if (delta < 0 && delta >= -3) {
memcpy(_overwrite, addr_at(bci + ilen + delta), -delta); memcpy(_overwrite, addr_at(bci + ilen + delta), -delta);
} }