8140594: Various minor code improvements (compiler)
authorgoetz
Tue, 03 May 2016 12:23:06 +0200
changeset 38658 34f9c45625d8
parent 38657 3caf062361a6
child 38659 18e0111df08a
8140594: Various minor code improvements (compiler) Summary: Various minor code improvements (compiler) Reviewed-by: thartmann, kvn
hotspot/src/os/linux/vm/os_linux.cpp
hotspot/src/os_cpu/linux_x86/vm/os_linux_x86.cpp
hotspot/src/share/vm/adlc/formssel.cpp
hotspot/src/share/vm/c1/c1_LinearScan.cpp
hotspot/src/share/vm/ci/ciMethodBlocks.cpp
hotspot/src/share/vm/classfile/classFileParser.cpp
hotspot/src/share/vm/classfile/classLoader.cpp
hotspot/src/share/vm/classfile/systemDictionary.cpp
hotspot/src/share/vm/compiler/compileBroker.cpp
hotspot/src/share/vm/compiler/compileLog.cpp
hotspot/src/share/vm/compiler/disassembler.cpp
hotspot/src/share/vm/logging/logTagSet.cpp
hotspot/src/share/vm/oops/constantPool.cpp
hotspot/src/share/vm/oops/generateOopMap.cpp
hotspot/src/share/vm/opto/block.cpp
hotspot/src/share/vm/opto/callnode.cpp
hotspot/src/share/vm/opto/graphKit.cpp
hotspot/src/share/vm/opto/matcher.cpp
hotspot/src/share/vm/runtime/relocator.cpp
--- a/hotspot/src/os/linux/vm/os_linux.cpp	Mon May 09 23:49:22 2016 -0700
+++ b/hotspot/src/os/linux/vm/os_linux.cpp	Tue May 03 12:23:06 2016 +0200
@@ -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;
--- a/hotspot/src/os_cpu/linux_x86/vm/os_linux_x86.cpp	Mon May 09 23:49:22 2016 -0700
+++ b/hotspot/src/os_cpu/linux_x86/vm/os_linux_x86.cpp	Tue May 03 12:23:06 2016 +0200
@@ -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
--- a/hotspot/src/share/vm/adlc/formssel.cpp	Mon May 09 23:49:22 2016 -0700
+++ b/hotspot/src/share/vm/adlc/formssel.cpp	Tue May 03 12:23:06 2016 +0200
@@ -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;
--- a/hotspot/src/share/vm/c1/c1_LinearScan.cpp	Mon May 09 23:49:22 2016 -0700
+++ b/hotspot/src/share/vm/c1/c1_LinearScan.cpp	Tue May 03 12:23:06 2016 +0200
@@ -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("           ");
         }
--- a/hotspot/src/share/vm/ci/ciMethodBlocks.cpp	Mon May 09 23:49:22 2016 -0700
+++ b/hotspot/src/share/vm/ci/ciMethodBlocks.cpp	Tue May 03 12:23:06 2016 +0200
@@ -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]);
     }
--- a/hotspot/src/share/vm/classfile/classFileParser.cpp	Mon May 09 23:49:22 2016 -0700
+++ b/hotspot/src/share/vm/classfile/classFileParser.cpp	Tue May 03 12:23:06 2016 +0200
@@ -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()) {
--- a/hotspot/src/share/vm/classfile/classLoader.cpp	Mon May 09 23:49:22 2016 -0700
+++ b/hotspot/src/share/vm/classfile/classLoader.cpp	Tue May 03 12:23:06 2016 +0200
@@ -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;
--- a/hotspot/src/share/vm/classfile/systemDictionary.cpp	Mon May 09 23:49:22 2016 -0700
+++ b/hotspot/src/share/vm/classfile/systemDictionary.cpp	Tue May 03 12:23:06 2016 +0200
@@ -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);
   }
--- a/hotspot/src/share/vm/compiler/compileBroker.cpp	Mon May 09 23:49:22 2016 -0700
+++ b/hotspot/src/share/vm/compiler/compileBroker.cpp	Tue May 03 12:23:06 2016 +0200
@@ -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);
--- a/hotspot/src/share/vm/compiler/compileLog.cpp	Mon May 09 23:49:22 2016 -0700
+++ b/hotspot/src/share/vm/compiler/compileLog.cpp	Tue May 03 12:23:06 2016 +0200
@@ -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("<fragment>");
           file->print_raw_cr("<![CDATA[");
--- a/hotspot/src/share/vm/compiler/disassembler.cpp	Mon May 09 23:49:22 2016 -0700
+++ b/hotspot/src/share/vm/compiler/disassembler.cpp	Tue May 03 12:23:06 2016 +0200
@@ -99,7 +99,7 @@
     const char* p = strrchr(buf, *os::file_separator());
     if (p != NULL) lib_offset = p - base + 1;
     p = strstr(p ? p : base, "jvm");
-    if (p != NULL)  jvm_offset = p - base;
+    if (p != NULL) jvm_offset = p - base;
   }
 #endif
   // Find the disassembler shared library.
@@ -113,13 +113,13 @@
     strcpy(&buf[jvm_offset], hsdis_library_name);
     strcat(&buf[jvm_offset], os::dll_file_extension());
     _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
       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. <home>/jre/lib/<arch>/hsdis-<arch>.so
       buf[lib_offset - 1] = '\0';
       const char* p = strrchr(buf, *os::file_separator());
--- a/hotspot/src/share/vm/logging/logTagSet.cpp	Mon May 09 23:49:22 2016 -0700
+++ b/hotspot/src/share/vm/logging/logTagSet.cpp	Tue May 03 12:23:06 2016 +0200
@@ -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 = 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);
--- a/hotspot/src/share/vm/oops/constantPool.cpp	Mon May 09 23:49:22 2016 -0700
+++ b/hotspot/src/share/vm/oops/constantPool.cpp	Tue May 03 12:23:06 2016 +0200
@@ -80,7 +80,8 @@
 
 ConstantPool::ConstantPool(Array<u1>* tags) :
   _tags(tags),
-  _length(tags->length()) {
+  _length(tags->length()),
+  _flags(0) {
 
     assert(_tags != NULL, "invariant");
     assert(tags->length() == _length, "invariant");
--- a/hotspot/src/share/vm/oops/generateOopMap.cpp	Mon May 09 23:49:22 2016 -0700
+++ b/hotspot/src/share/vm/oops/generateOopMap.cpp	Tue May 03 12:23:06 2016 +0200
@@ -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++;
--- a/hotspot/src/share/vm/opto/block.cpp	Mon May 09 23:49:22 2016 -0700
+++ b/hotspot/src/share/vm/opto/block.cpp	Tue May 03 12:23:06 2016 +0200
@@ -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;
--- a/hotspot/src/share/vm/opto/callnode.cpp	Mon May 09 23:49:22 2016 -0700
+++ b/hotspot/src/share/vm/opto/callnode.cpp	Tue May 03 12:23:06 2016 +0200
@@ -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);
--- a/hotspot/src/share/vm/opto/graphKit.cpp	Mon May 09 23:49:22 2016 -0700
+++ b/hotspot/src/share/vm/opto/graphKit.cpp	Tue May 03 12:23:06 2016 +0200
@@ -1079,7 +1079,7 @@
   case Bytecodes::_freturn:
   case Bytecodes::_dreturn:
   case Bytecodes::_areturn:
-    assert(rsize = -depth, "");
+    assert(rsize == -depth, "");
     inputs = rsize;
     break;
 
--- a/hotspot/src/share/vm/opto/matcher.cpp	Mon May 09 23:49:22 2016 -0700
+++ b/hotspot/src/share/vm/opto/matcher.cpp	Tue May 03 12:23:06 2016 +0200
@@ -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;
--- a/hotspot/src/share/vm/runtime/relocator.cpp	Mon May 09 23:49:22 2016 -0700
+++ b/hotspot/src/share/vm/runtime/relocator.cpp	Tue May 03 12:23:06 2016 +0200
@@ -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);
   }