# HG changeset patch # User goetz # Date 1462270986 -7200 # Node ID fc6ae51c40957b33f80a0ce51470a4754f115103 # Parent 481284d8ed27e012f773611db06263a2ce377889 8140594: Various minor code improvements (compiler) Reviewed-by: thartmann diff --git a/src/os/linux/vm/os_linux.cpp b/src/os/linux/vm/os_linux.cpp --- a/src/os/linux/vm/os_linux.cpp +++ b/src/os/linux/vm/os_linux.cpp @@ -1913,9 +1913,10 @@ return false; } - char buf[32]; + char buf[33]; 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); } @@ -6033,8 +6034,8 @@ if (core_pattern[0] == '|') { written = jio_snprintf(buffer, bufferSize, - "\"%s\" (or dumping to %s/core.%d)", - &core_pattern[1], p, current_process_id()); + "\"%s\" (or dumping to %s/core.%d)", + &core_pattern[1], p, current_process_id()); } else { written = jio_snprintf(buffer, bufferSize, "%s/%s", p, core_pattern); } @@ -6067,20 +6068,20 @@ char *p = &buf[len]; jio_snprintf(p, buflen-len, - "\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" - "Enter 'yes' to launch gdb automatically (PATH must include gdb)\n" - "Otherwise, press RETURN to abort...", - os::current_process_id(), os::current_process_id(), - os::current_thread_id(), os::current_thread_id()); + "\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" + "Enter 'yes' to launch gdb automatically (PATH must include gdb)\n" + "Otherwise, press RETURN to abort...", + os::current_process_id(), os::current_process_id(), + os::current_thread_id(), os::current_thread_id()); bool yes = os::message_box("Unexpected Error", buf); if (yes) { // yes, user asked VM to launch debugger - jio_snprintf(buf, sizeof(buf), "gdb /proc/%d/exe %d", - os::current_process_id(), os::current_process_id()); + jio_snprintf(buf, sizeof(char)*buflen, "gdb /proc/%d/exe %d", + os::current_process_id(), os::current_process_id()); os::fork_and_exec(buf); yes = false; diff --git a/src/os_cpu/linux_x86/vm/os_linux_x86.cpp b/src/os_cpu/linux_x86/vm/os_linux_x86.cpp --- a/src/os_cpu/linux_x86/vm/os_linux_x86.cpp +++ b/src/os_cpu/linux_x86/vm/os_linux_x86.cpp @@ -823,7 +823,7 @@ intptr_t *sp = (intptr_t *)os::Linux::ucontext_get_sp(uc); 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(); // Note: it may be unsafe to inspect memory near pc. For example, pc may diff --git a/src/share/vm/adlc/formssel.cpp b/src/share/vm/adlc/formssel.cpp --- a/src/share/vm/adlc/formssel.cpp +++ b/src/share/vm/adlc/formssel.cpp @@ -1499,7 +1499,8 @@ // twice, we need to check that the operands are pointer-eequivalent in // the DFA during the labeling process. 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 MatchNode *mnode = @@ -1508,12 +1509,12 @@ uint first = 1; // Start with the predicate supplied in the .ad file. - if( _predicate ) { - if( first ) first=0; - strcpy(s,"("); s += strlen(s); - strcpy(s,_predicate->_pred); + if (_predicate) { + if (first) first = 0; + strcpy(s, "("); s += strlen(s); + strncpy(s, _predicate->_pred, buflen - strlen(s) - 1); s += strlen(s); - strcpy(s,")"); s += strlen(s); + strcpy(s, ")"); s += strlen(s); } for( DictI i(&names); i.test(); ++i ) { uintptr_t cnt = (uintptr_t)i._value; diff --git a/src/share/vm/c1/c1_LinearScan.cpp b/src/share/vm/c1/c1_LinearScan.cpp --- a/src/share/vm/c1/c1_LinearScan.cpp +++ b/src/share/vm/c1/c1_LinearScan.cpp @@ -5521,7 +5521,8 @@ } } - 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; } @@ -6497,8 +6498,9 @@ if (_counters_sum[i] > 0 || _counters_max[i] >= 0) { tty->print("%25s: %8d", counter_name(i), _counters_sum[i]); - if (base_counter(i) != invalid_counter) { - tty->print(" (%5.1f%%) ", _counters_sum[i] * 100.0 / _counters_sum[base_counter(i)]); + LinearScanStatistic::Counter cntr = base_counter(i); + if (cntr != invalid_counter) { + tty->print(" (%5.1f%%) ", _counters_sum[i] * 100.0 / _counters_sum[cntr]); } else { tty->print(" "); } diff --git a/src/share/vm/ci/ciMethodBlocks.cpp b/src/share/vm/ci/ciMethodBlocks.cpp --- a/src/share/vm/ci/ciMethodBlocks.cpp +++ b/src/share/vm/ci/ciMethodBlocks.cpp @@ -372,7 +372,7 @@ void ciBlock::dump() { 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) { tty->print(" %s", flagnames[i]); } diff --git a/src/share/vm/classfile/classFileParser.cpp b/src/share/vm/classfile/classFileParser.cpp --- a/src/share/vm/classfile/classFileParser.cpp +++ b/src/share/vm/classfile/classFileParser.cpp @@ -1401,9 +1401,11 @@ FieldAllocationType update(bool is_static, BasicType type) { FieldAllocationType atype = basic_type_to_atype(is_static, type); - // Make sure there is no overflow with injected fields. - assert(count[atype] < 0xFFFF, "More than 65535 fields"); - count[atype]++; + if (atype != BAD_ALLOCATION_TYPE) { + // Make sure there is no overflow with injected fields. + assert(count[atype] < 0xFFFF, "More than 65535 fields"); + count[atype]++; + } return atype; } }; @@ -3335,8 +3337,9 @@ } } else if (tag == vmSymbols::tag_bootstrap_methods() && _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); + } parsed_bootstrap_methods_attribute = true; parse_classfile_bootstrap_methods_attribute(cfs, cp, attribute_length, CHECK); } else if (tag == vmSymbols::tag_runtime_visible_type_annotations()) { diff --git a/src/share/vm/classfile/classLoader.cpp b/src/share/vm/classfile/classLoader.cpp --- a/src/share/vm/classfile/classLoader.cpp +++ b/src/share/vm/classfile/classLoader.cpp @@ -305,11 +305,9 @@ } if (is_multi_ver) { - int n; char entry_name[JVM_MAXPATHLEN]; if (version > 0) { - n = jio_snprintf(entry_name, sizeof(entry_name), "META-INF/versions/%d/%s", version, name); - entry_name[n] = '\0'; + jio_snprintf(entry_name, sizeof(entry_name), "META-INF/versions/%d/%s", version, name); buffer = open_entry((const char*)entry_name, filesize, false, CHECK_NULL); if (buffer == NULL) { warning("Could not find %s in %s, try to find highest version instead", entry_name, _zip_name); @@ -317,8 +315,7 @@ } if (buffer == NULL) { for (int i = cur_ver; i >= base_version; i--) { - n = jio_snprintf(entry_name, sizeof(entry_name), "META-INF/versions/%d/%s", i, name); - entry_name[n] = '\0'; + jio_snprintf(entry_name, sizeof(entry_name), "META-INF/versions/%d/%s", i, name); buffer = open_entry((const char*)entry_name, filesize, false, CHECK_NULL); if (buffer != NULL) { break; diff --git a/src/share/vm/classfile/systemDictionary.cpp b/src/share/vm/classfile/systemDictionary.cpp --- a/src/share/vm/classfile/systemDictionary.cpp +++ b/src/share/vm/classfile/systemDictionary.cpp @@ -1160,10 +1160,10 @@ while ((index = strchr(name, '/')) != NULL) { *index = '.'; // replace '/' with '.' in package name } - const char* fmt = "Prohibited package name: %s"; - size_t len = strlen(fmt) + strlen(name); + const char* msg_text = "Prohibited package name: "; + size_t len = strlen(msg_text) + strlen(name) + 1; 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, vmSymbols::java_lang_SecurityException(), message); } diff --git a/src/share/vm/compiler/compileBroker.cpp b/src/share/vm/compiler/compileBroker.cpp --- a/src/share/vm/compiler/compileBroker.cpp +++ b/src/share/vm/compiler/compileBroker.cpp @@ -2392,10 +2392,9 @@ // Debugging output for failure void CompileBroker::print_last_compile() { - if ( _last_compile_level != CompLevel_none && - compiler(_last_compile_level) != NULL && - _last_method_compiled != NULL && - _last_compile_type != no_compile) { + if (_last_compile_level != CompLevel_none && + compiler(_last_compile_level) != NULL && + _last_compile_type != no_compile) { if (_last_compile_type == osr_compile) { tty->print_cr("Last parse: [osr]%d+++(%d) %s", _osr_compilation_id, _last_compile_level, _last_method_compiled); diff --git a/src/share/vm/compiler/compileLog.cpp b/src/share/vm/compiler/compileLog.cpp --- a/src/share/vm/compiler/compileLog.cpp +++ b/src/share/vm/compiler/compileLog.cpp @@ -231,7 +231,8 @@ // Copy any remaining data inside a quote: bool saw_slop = false; 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) { file->print_raw_cr(""); file->print_raw_cr("= 0) { // 2. /jre/lib///hsdis-.so strcpy(&buf[lib_offset], hsdis_library_name); strcat(&buf[lib_offset], os::dll_file_extension()); _library = os::dll_load(buf, ebuf, sizeof ebuf); } - if (_library == NULL) { + if (_library == NULL && lib_offset > 0) { // 3. /jre/lib//hsdis-.so buf[lib_offset - 1] = '\0'; const char* p = strrchr(buf, *os::file_separator()); diff --git a/src/share/vm/logging/logTagSet.cpp b/src/share/vm/logging/logTagSet.cpp --- a/src/share/vm/logging/logTagSet.cpp +++ b/src/share/vm/logging/logTagSet.cpp @@ -104,12 +104,18 @@ va_copy(saved_args, args); size_t prefix_len = _write_prefix(buf, sizeof(buf)); // 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 = prefix_len + os::log_vsnprintf(buf, sizeof(buf), fmt, args); + } assert(ret >= 0, "Log message buffer issue"); if ((size_t)ret >= sizeof(buf)) { size_t newbuf_len = prefix_len + ret + 1; 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); assert(ret >= 0, "Log message buffer issue"); log(level, newbuf); diff --git a/src/share/vm/oops/constantPool.cpp b/src/share/vm/oops/constantPool.cpp --- a/src/share/vm/oops/constantPool.cpp +++ b/src/share/vm/oops/constantPool.cpp @@ -80,7 +80,8 @@ ConstantPool::ConstantPool(Array* tags) : _tags(tags), - _length(tags->length()) { + _length(tags->length()), + _flags(0) { assert(_tags != NULL, "invariant"); assert(tags->length() == _length, "invariant"); diff --git a/src/share/vm/oops/generateOopMap.cpp b/src/share/vm/oops/generateOopMap.cpp --- a/src/share/vm/oops/generateOopMap.cpp +++ b/src/share/vm/oops/generateOopMap.cpp @@ -1678,8 +1678,14 @@ CellTypeState actual[5]; assert(poplen < 5, "this must be less than length of actual vector"); - // pop all arguments - for(int i = 0; i < poplen; i++) actual[i] = pop(); + // Pop all arguments. + 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 char push_ch = *out++; diff --git a/src/share/vm/opto/block.cpp b/src/share/vm/opto/block.cpp --- a/src/share/vm/opto/block.cpp +++ b/src/share/vm/opto/block.cpp @@ -1430,7 +1430,7 @@ if (n->num_preds() != 1) break; i++; - assert(n = _cfg.get_block(i), "expecting next block"); + assert(n == _cfg.get_block(i), "expecting next block"); tr->append(n); uf->map(n->_pre_order, tr->id()); traces[n->_pre_order] = NULL; diff --git a/src/share/vm/opto/callnode.cpp b/src/share/vm/opto/callnode.cpp --- a/src/share/vm/opto/callnode.cpp +++ b/src/share/vm/opto/callnode.cpp @@ -256,6 +256,7 @@ JVMState::JVMState(ciMethod* method, JVMState* caller) : _method(method) { assert(method != NULL, "must be valid call site"); + _bci = InvocationEntryBci; _reexecute = Reexecute_Undefined; debug_only(_bci = -99); // random garbage value debug_only(_map = (SafePointNode*)-1); diff --git a/src/share/vm/opto/graphKit.cpp b/src/share/vm/opto/graphKit.cpp --- a/src/share/vm/opto/graphKit.cpp +++ b/src/share/vm/opto/graphKit.cpp @@ -1079,7 +1079,7 @@ case Bytecodes::_freturn: case Bytecodes::_dreturn: case Bytecodes::_areturn: - assert(rsize = -depth, ""); + assert(rsize == -depth, ""); inputs = rsize; break; diff --git a/src/share/vm/opto/matcher.cpp b/src/share/vm/opto/matcher.cpp --- a/src/share/vm/opto/matcher.cpp +++ b/src/share/vm/opto/matcher.cpp @@ -659,11 +659,14 @@ 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 ); // 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 - // Need two slots for ptrs in 64-bit land - reth_rms[TypeFunc::Parms].Insert(OptoReg::add(OptoReg::Name(find_receiver(false)),1)); + // Need two slots for ptrs in 64-bit land + reth_rms[TypeFunc::Parms].Insert(OptoReg::add(OptoReg::Name(reg), 1)); #endif + } // Input RegMask array shared by all TailCalls uint tail_call_edge_cnt = TypeFunc::Parms+2; diff --git a/src/share/vm/runtime/relocator.cpp b/src/share/vm/runtime/relocator.cpp --- a/src/share/vm/runtime/relocator.cpp +++ b/src/share/vm/runtime/relocator.cpp @@ -612,8 +612,8 @@ // 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 // 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); }