8207049: Minor improvements of compiler code.
authorgoetz
Thu, 12 Jul 2018 16:31:28 +0200
changeset 51078 fc6cfe40e32a
parent 51077 9baa91bc7567
child 51079 9e19d3a1a69d
8207049: Minor improvements of compiler code. Reviewed-by: kvn, mdoerr
src/hotspot/cpu/x86/x86.ad
src/hotspot/share/adlc/archDesc.cpp
src/hotspot/share/adlc/arena.cpp
src/hotspot/share/adlc/dfa.cpp
src/hotspot/share/adlc/filebuff.cpp
src/hotspot/share/adlc/formssel.cpp
src/hotspot/share/adlc/main.cpp
src/hotspot/share/adlc/output_c.cpp
src/hotspot/share/asm/codeBuffer.cpp
src/hotspot/share/c1/c1_IR.cpp
src/hotspot/share/c1/c1_LinearScan.cpp
src/hotspot/share/code/codeCache.cpp
src/hotspot/share/compiler/compileLog.cpp
src/hotspot/share/compiler/disassembler.cpp
src/hotspot/share/compiler/methodLiveness.cpp
src/hotspot/share/compiler/oopMap.cpp
src/hotspot/share/jvmci/jvmciCodeInstaller.cpp
src/hotspot/share/jvmci/jvmciCompilerToVM.cpp
src/hotspot/share/opto/arraycopynode.cpp
src/hotspot/share/opto/bytecodeInfo.cpp
src/hotspot/share/opto/callnode.cpp
src/hotspot/share/opto/compile.cpp
src/hotspot/share/opto/gcm.cpp
src/hotspot/share/opto/ifnode.cpp
src/hotspot/share/opto/indexSet.cpp
src/hotspot/share/opto/lcm.cpp
src/hotspot/share/opto/loopPredicate.cpp
src/hotspot/share/opto/loopTransform.cpp
src/hotspot/share/opto/macro.cpp
src/hotspot/share/opto/memnode.cpp
src/hotspot/share/opto/node.hpp
src/hotspot/share/opto/output.cpp
src/hotspot/share/opto/parse1.cpp
src/hotspot/share/opto/reg_split.cpp
src/hotspot/share/opto/runtime.cpp
src/hotspot/share/opto/type.cpp
src/hotspot/share/runtime/simpleThresholdPolicy.cpp
--- a/src/hotspot/cpu/x86/x86.ad	Fri Jul 13 11:21:55 2018 +0800
+++ b/src/hotspot/cpu/x86/x86.ad	Thu Jul 12 16:31:28 2018 +0200
@@ -1,5 +1,5 @@
 //
-// Copyright (c) 2011, 2017, Oracle and/or its affiliates. All rights reserved.
+// Copyright (c) 2011, 2018, 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
@@ -1444,6 +1444,7 @@
       case Op_CMoveVF:
         if (vlen != 8)
           ret_value  = false;
+        break;
       case Op_CMoveVD:
         if (vlen != 4)
           ret_value  = false;
--- a/src/hotspot/share/adlc/archDesc.cpp	Fri Jul 13 11:21:55 2018 +0800
+++ b/src/hotspot/share/adlc/archDesc.cpp	Thu Jul 12 16:31:28 2018 +0200
@@ -1,5 +1,5 @@
 //
-// Copyright (c) 1997, 2017, Oracle and/or its affiliates. All rights reserved.
+// Copyright (c) 1997, 2018, 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
@@ -543,14 +543,18 @@
   }
 
   // Identify index position among ideal operands
-  intptr_t    index     = _last_opcode;
-  const char *indexStr  = node ? node->_opType : (char *) " ";
-  index            = (intptr_t)_idealIndex[indexStr];
+  intptr_t index = _last_opcode;
+  const char *indexStr = node ? node->_opType : (char *) " ";
+  index = (intptr_t)_idealIndex[indexStr];
   if (index == 0) {
     fprintf(stderr, "error: operand \"%s\" not found\n", indexStr);
     assert(0, "fatal error");
   }
 
+  if (node == NULL) {
+    fprintf(stderr, "error: node is NULL\n");
+    assert(0, "fatal error");
+  }
   // Build MatchLists for children
   // Check each child for an internal operand name, and use that name
   // for the parent's matchlist entry if it exists
--- a/src/hotspot/share/adlc/arena.cpp	Fri Jul 13 11:21:55 2018 +0800
+++ b/src/hotspot/share/adlc/arena.cpp	Thu Jul 12 16:31:28 2018 +0200
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1998, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1998, 2018, 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
@@ -43,7 +43,7 @@
   while( k ) {
     Chunk *tmp = k->_next;
     // clear out this chunk (to detect allocation bugs)
-    memset(k, 0xBAADBABE, k->_len);
+    memset(k, 0xBE, k->_len);
     free(k);                    // Free chunk (was malloc'd)
     k = tmp;
   }
--- a/src/hotspot/share/adlc/dfa.cpp	Fri Jul 13 11:21:55 2018 +0800
+++ b/src/hotspot/share/adlc/dfa.cpp	Thu Jul 12 16:31:28 2018 +0200
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2018, 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
@@ -502,9 +502,11 @@
     case '"':  // such as: #line 10 "myfile.ad"\n mypredicate
       return true;
     case '|':
-      if( prev != pred && *(prev-1) == '|' ) return true;
+      if (prev != pred && *(prev-1) == '|') return true;
+      break;
     case '&':
-      if( prev != pred && *(prev-1) == '&' ) return true;
+      if (prev != pred && *(prev-1) == '&') return true;
+      break;
     default:
       return false;
     }
@@ -717,21 +719,21 @@
 
   // Preserve use of external name which has a zero value
   if( c1->_external_name != NULL ) {
-    sprintf( string_buffer, "%s", c1->as_string());
+    sprintf(string_buffer, "%s", c1->as_string());
     if( !c2->is_zero() ) {
-      strcat( string_buffer, "+");
-      strcat( string_buffer, c2->as_string());
+      strncat(string_buffer, "+", STRING_BUFFER_LENGTH);
+      strncat(string_buffer, c2->as_string(), STRING_BUFFER_LENGTH);
     }
     result = strdup(string_buffer);
   }
   else if( c2->_external_name != NULL ) {
     if( !c1->is_zero() ) {
-      sprintf( string_buffer, "%s", c1->as_string());
-      strcat( string_buffer, " + ");
+      sprintf(string_buffer, "%s", c1->as_string());
+      strncat(string_buffer, " + ", STRING_BUFFER_LENGTH);
     } else {
       string_buffer[0] = '\0';
     }
-    strcat( string_buffer, c2->_external_name );
+    strncat(string_buffer, c2->_external_name, STRING_BUFFER_LENGTH);
     result = strdup(string_buffer);
   }
   return result;
@@ -741,8 +743,8 @@
   if( !c1->is_zero() ) {
     sprintf( string_buffer, "%s", c1->_expr);
     if( !c2->is_zero() ) {
-      strcat( string_buffer, "+");
-      strcat( string_buffer, c2->_expr);
+      strncat(string_buffer, "+", STRING_BUFFER_LENGTH);
+      strncat(string_buffer, c2->_expr, STRING_BUFFER_LENGTH);
     }
   }
   else if( !c2->is_zero() ) {
--- a/src/hotspot/share/adlc/filebuff.cpp	Fri Jul 13 11:21:55 2018 +0800
+++ b/src/hotspot/share/adlc/filebuff.cpp	Thu Jul 12 16:31:28 2018 +0200
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2018, 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
@@ -95,8 +95,11 @@
   va_start(args, fmt);
   switch (flag) {
   case 0: _AD._warnings += _AD.emit_msg(0, flag, linenum, fmt, args);
+    break;
   case 1: _AD._syntax_errs += _AD.emit_msg(0, flag, linenum, fmt, args);
+    break;
   case 2: _AD._semantic_errs += _AD.emit_msg(0, flag, linenum, fmt, args);
+    break;
   default: assert(0, ""); break;
   }
   va_end(args);
--- a/src/hotspot/share/adlc/formssel.cpp	Fri Jul 13 11:21:55 2018 +0800
+++ b/src/hotspot/share/adlc/formssel.cpp	Thu Jul 12 16:31:28 2018 +0200
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1998, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1998, 2018, 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
@@ -3634,7 +3634,7 @@
         && (is_load_from_memory(mRule2->_opType) == data_type) // reg vs. (load memory)
         && (name_left != NULL)       // NOT (load)
         && (name_right == NULL) ) {  // NOT (load memory foo)
-      const Form *form2_left = name_left ? globals[name_left] : NULL;
+      const Form *form2_left = globals[name_left];
       if( form2_left && form2_left->is_cisc_mem(globals) ) {
         cisc_spillable = Is_cisc_spillable;
         operand        = _name;
@@ -3645,7 +3645,7 @@
       }
     }
     // Detect reg vs memory
-    else if( form->is_cisc_reg(globals) && form2->is_cisc_mem(globals) ) {
+    else if (form->is_cisc_reg(globals) && form2 != NULL && form2->is_cisc_mem(globals)) {
       cisc_spillable = Is_cisc_spillable;
       operand        = _name;
       reg_type       = _result;
@@ -3710,8 +3710,12 @@
   }
 
   // Check right operands: recursive walk to identify reg->mem operand
-  if( (_rChild == NULL) && (mRule2->_rChild == NULL) ) {
-    right_spillable =  Maybe_cisc_spillable;
+  if (_rChild == NULL) {
+    if (mRule2->_rChild == NULL) {
+      right_spillable =  Maybe_cisc_spillable;
+    } else {
+      assert(0, "_rChild should not be NULL");
+    }
   } else {
     right_spillable = _rChild->cisc_spill_match(globals, registers, mRule2->_rChild, operand, reg_type);
   }
--- a/src/hotspot/share/adlc/main.cpp	Fri Jul 13 11:21:55 2018 +0800
+++ b/src/hotspot/share/adlc/main.cpp	Thu Jul 12 16:31:28 2018 +0200
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1997, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2018, 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
@@ -142,7 +142,7 @@
       const char *base = strip_ext(strdup(argv[i]));
       char       *temp = base_plus_suffix("dfa_",base);
       AD._DFA_file._name = base_plus_suffix(temp,".cpp");
-      delete temp;
+      delete[] temp;
       temp = base_plus_suffix("ad_",base);
       AD._CPP_file._name          = base_plus_suffix(temp,".cpp");
       AD._CPP_CLONE_file._name    = base_plus_suffix(temp,"_clone.cpp");
@@ -153,13 +153,13 @@
       AD._CPP_PEEPHOLE_file._name = base_plus_suffix(temp,"_peephole.cpp");
       AD._CPP_PIPELINE_file._name = base_plus_suffix(temp,"_pipeline.cpp");
       AD._HPP_file._name = base_plus_suffix(temp,".hpp");
-      delete temp;
+      delete[] temp;
       temp = base_plus_suffix("adGlobals_",base);
       AD._VM_file._name = base_plus_suffix(temp,".hpp");
-      delete temp;
+      delete[] temp;
       temp = base_plus_suffix("bugs_",base);
       AD._bug_file._name = base_plus_suffix(temp,".out");
-      delete temp;
+      delete[] temp;
     }                           // End of files vs options...
   }                             // End of while have command line arguments
 
--- a/src/hotspot/share/adlc/output_c.cpp	Fri Jul 13 11:21:55 2018 +0800
+++ b/src/hotspot/share/adlc/output_c.cpp	Thu Jul 12 16:31:28 2018 +0200
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1998, 2017, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1998, 2018, 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
@@ -1936,6 +1936,7 @@
           _AD.syntax_err( _ins_encode._linenum,
                           "Parameter %s not passed to enc_class %s from instruct %s.\n",
                           rep_var, _encoding._name, _inst._ident);
+          assert(false, "inst_rep_var == NULL, cannot continue.");
         }
 
         // Check if instruction's actual parameter is a local name in the instruction
@@ -1976,8 +1977,8 @@
         }
         else {
           // Check for unimplemented functionality before hard failure
-          assert( strcmp(opc->_ident,"label")==0, "Unimplemented() Label");
-          assert( false, "ShouldNotReachHere()");
+          assert(opc != NULL && strcmp(opc->_ident, "label") == 0, "Unimplemented Label");
+          assert(false, "ShouldNotReachHere()");
         }
       } // done checking which operand this is.
     } else {
@@ -2450,8 +2451,8 @@
       }
       else {
         // Check for unimplemented functionality before hard failure
-        assert( strcmp(opc->_ident,"label")==0, "Unimplemented() Label");
-        assert( false, "ShouldNotReachHere()");
+        assert(opc != NULL && strcmp(opc->_ident, "label") == 0, "Unimplemented Label");
+        assert(false, "ShouldNotReachHere()");
       }
       // all done
     }
@@ -3305,9 +3306,11 @@
   // Output the definitions for machine node specific pipeline data
   _machnodes.reset();
 
-  for ( ; (machnode = (MachNodeForm*)_machnodes.iter()) != NULL; ) {
-    fprintf(_CPP_PIPELINE_file._fp, "const Pipeline * %sNode::pipeline() const { return (&pipeline_class_%03d); }\n",
-      machnode->_ident, ((class PipeClassForm *)_pipeline->_classdict[machnode->_machnode_pipe])->_num);
+  if (_pipeline != NULL) {
+    for ( ; (machnode = (MachNodeForm*)_machnodes.iter()) != NULL; ) {
+      fprintf(_CPP_PIPELINE_file._fp, "const Pipeline * %sNode::pipeline() const { return (&pipeline_class_%03d); }\n",
+              machnode->_ident, ((class PipeClassForm *)_pipeline->_classdict[machnode->_machnode_pipe])->_num);
+    }
   }
 
   fprintf(_CPP_PIPELINE_file._fp, "\n");
@@ -3315,13 +3318,15 @@
   // Output the definitions for instruction pipeline static data references
   _instructions.reset();
 
-  for ( ; (instr = (InstructForm*)_instructions.iter()) != NULL; ) {
-    if (instr->_ins_pipe && _pipeline->_classlist.search(instr->_ins_pipe)) {
-      fprintf(_CPP_PIPELINE_file._fp, "\n");
-      fprintf(_CPP_PIPELINE_file._fp, "const Pipeline * %*sNode::pipeline_class() { return (&pipeline_class_%03d); }\n",
-        max_ident_len, instr->_ident, ((class PipeClassForm *)_pipeline->_classdict[instr->_ins_pipe])->_num);
-      fprintf(_CPP_PIPELINE_file._fp, "const Pipeline * %*sNode::pipeline() const { return (&pipeline_class_%03d); }\n",
-        max_ident_len, instr->_ident, ((class PipeClassForm *)_pipeline->_classdict[instr->_ins_pipe])->_num);
+  if (_pipeline != NULL) {
+    for ( ; (instr = (InstructForm*)_instructions.iter()) != NULL; ) {
+      if (instr->_ins_pipe && _pipeline->_classlist.search(instr->_ins_pipe)) {
+        fprintf(_CPP_PIPELINE_file._fp, "\n");
+        fprintf(_CPP_PIPELINE_file._fp, "const Pipeline * %*sNode::pipeline_class() { return (&pipeline_class_%03d); }\n",
+                max_ident_len, instr->_ident, ((class PipeClassForm *)_pipeline->_classdict[instr->_ins_pipe])->_num);
+        fprintf(_CPP_PIPELINE_file._fp, "const Pipeline * %*sNode::pipeline() const { return (&pipeline_class_%03d); }\n",
+                max_ident_len, instr->_ident, ((class PipeClassForm *)_pipeline->_classdict[instr->_ins_pipe])->_num);
+      }
     }
   }
 }
--- a/src/hotspot/share/asm/codeBuffer.cpp	Fri Jul 13 11:21:55 2018 +0800
+++ b/src/hotspot/share/asm/codeBuffer.cpp	Thu Jul 12 16:31:28 2018 +0200
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2018, 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
@@ -187,7 +187,7 @@
   cs->_limit = new_limit;
   cs->_locs_limit = new_locs_limit;
   cs->_frozen = true;
-  if (!next_cs->is_allocated() && !next_cs->is_frozen()) {
+  if (next_cs != NULL && !next_cs->is_allocated() && !next_cs->is_frozen()) {
     // Give remaining buffer space to the following section.
     next_cs->initialize(new_limit, old_limit - new_limit);
     next_cs->initialize_shared_locs(new_locs_limit,
@@ -494,10 +494,13 @@
       // Compute initial padding; assign it to the previous non-empty guy.
       // Cf. figure_expanded_capacities.
       csize_t padding = cs->align_at_start(buf_offset) - buf_offset;
-      if (padding != 0) {
-        buf_offset += padding;
-        assert(prev_dest_cs != NULL, "sanity");
-        prev_dest_cs->_limit += padding;
+      if (prev_dest_cs != NULL) {
+        if (padding != 0) {
+          buf_offset += padding;
+          prev_dest_cs->_limit += padding;
+        }
+      } else {
+        guarantee(padding == 0, "In first iteration no padding should be needed.");
       }
       #ifdef ASSERT
       if (prev_cs != NULL && prev_cs->is_frozen() && n < (SECT_LIMIT - 1)) {
--- a/src/hotspot/share/c1/c1_IR.cpp	Fri Jul 13 11:21:55 2018 +0800
+++ b/src/hotspot/share/c1/c1_IR.cpp	Thu Jul 12 16:31:28 2018 +0200
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1999, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1999, 2018, 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
@@ -1386,7 +1386,7 @@
     n->values_do(this);
     // need to remove this instruction from the instruction stream
     if (n->subst() != n) {
-      assert(last != NULL, "must have last");
+      guarantee(last != NULL, "must have last");
       last->set_next(n->next());
     } else {
       last = n;
--- a/src/hotspot/share/c1/c1_LinearScan.cpp	Fri Jul 13 11:21:55 2018 +0800
+++ b/src/hotspot/share/c1/c1_LinearScan.cpp	Thu Jul 12 16:31:28 2018 +0200
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2005, 2017, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2005, 2018, 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
@@ -3954,7 +3954,7 @@
     if (!processed_interval) {
       // no move could be processed because there is a cycle in the move list
       // (e.g. r1 -> r2, r2 -> r1), so one interval must be spilled to memory
-      assert(spill_candidate != -1, "no interval in register for spilling found");
+      guarantee(spill_candidate != -1, "no interval in register for spilling found");
 
       // create a new spill interval and assign a stack slot to it
       Interval* from_interval = _mapping_from.at(spill_candidate);
@@ -6301,7 +6301,8 @@
                   assert(prev_branch->cond() == prev_cmp->condition(), "should be the same");
                 }
               }
-              assert(prev_cmp != NULL, "should have found comp instruction for branch");
+              // Guarantee because it is dereferenced below.
+              guarantee(prev_cmp != NULL, "should have found comp instruction for branch");
               if (prev_branch->block() == code->at(i + 1) && prev_branch->info() == NULL) {
 
                 TRACE_LINEAR_SCAN(3, tty->print_cr("Negating conditional branch and deleting unconditional branch at end of block B%d", block->block_id()));
--- a/src/hotspot/share/code/codeCache.cpp	Fri Jul 13 11:21:55 2018 +0800
+++ b/src/hotspot/share/code/codeCache.cpp	Thu Jul 12 16:31:28 2018 +0200
@@ -1363,22 +1363,22 @@
       const char *msg1 = msg1_stream.as_string();
       const char *msg2 = msg2_stream.as_string();
 
-      log_warning(codecache)(msg1);
-      log_warning(codecache)(msg2);
-      warning(msg1);
-      warning(msg2);
+      log_warning(codecache)("%s", msg1);
+      log_warning(codecache)("%s", msg2);
+      warning("%s", msg1);
+      warning("%s", msg2);
     } else {
       const char *msg1 = "CodeCache is full. Compiler has been disabled.";
       const char *msg2 = "Try increasing the code cache size using -XX:ReservedCodeCacheSize=";
 
-      log_warning(codecache)(msg1);
-      log_warning(codecache)(msg2);
-      warning(msg1);
-      warning(msg2);
+      log_warning(codecache)("%s", msg1);
+      log_warning(codecache)("%s", msg2);
+      warning("%s", msg1);
+      warning("%s", msg2);
     }
     ResourceMark rm;
     stringStream s;
-    // Dump code cache  into a buffer before locking the tty,
+    // Dump code cache into a buffer before locking the tty.
     {
       MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
       print_summary(&s);
--- a/src/hotspot/share/compiler/compileLog.cpp	Fri Jul 13 11:21:55 2018 +0800
+++ b/src/hotspot/share/compiler/compileLog.cpp	Thu Jul 12 16:31:28 2018 +0200
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2002, 2017, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2002, 2018, 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
@@ -217,14 +217,17 @@
       file->print_raw_cr("'>");
 
       size_t nr; // number read into buf from partial log
+      // In case of unsuccessful completion, read returns -1.
+      ssize_t bytes_read;
       // Copy data up to the end of the last <event> element:
       julong to_read = log->_file_end;
       while (to_read > 0) {
         if (to_read < (julong)buflen)
               nr = (size_t)to_read;
         else  nr = buflen;
-        nr = read(partial_fd, buf, (int)nr);
-        if (nr <= 0)  break;
+        bytes_read = read(partial_fd, buf, (int)nr);
+        if (bytes_read <= 0) break;
+        nr = bytes_read;
         to_read -= (julong)nr;
         file->write(buf, nr);
       }
@@ -232,7 +235,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-1)) > 0) {
+      while ((bytes_read = read(partial_fd, buf, buflen-1)) > 0) {
+        nr = bytes_read;
         buf[buflen-1] = '\0';
         if (!saw_slop) {
           file->print_raw_cr("<fragment>");
--- a/src/hotspot/share/compiler/disassembler.cpp	Fri Jul 13 11:21:55 2018 +0800
+++ b/src/hotspot/share/compiler/disassembler.cpp	Thu Jul 12 16:31:28 2018 +0200
@@ -122,7 +122,7 @@
     _decode_instructions_virtual = CAST_TO_FN_PTR(Disassembler::decode_func_virtual,
                                           os::dll_lookup(_library, decode_instructions_virtual_name));
   }
-  if (_decode_instructions_virtual == NULL) {
+  if (_decode_instructions_virtual == NULL && _library != NULL) {
     // could not spot in new version, try old version
     _decode_instructions = CAST_TO_FN_PTR(Disassembler::decode_func,
                                           os::dll_lookup(_library, decode_instructions_name));
--- a/src/hotspot/share/compiler/methodLiveness.cpp	Fri Jul 13 11:21:55 2018 +0800
+++ b/src/hotspot/share/compiler/methodLiveness.cpp	Thu Jul 12 16:31:28 2018 +0200
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1998, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1998, 2018, 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
@@ -484,7 +484,7 @@
     while (block == NULL && t > 0) {
      block = _block_map->at(--t);
     }
-    assert( block != NULL, "invalid bytecode index; must be instruction index" );
+    guarantee(block != NULL, "invalid bytecode index; must be instruction index");
     assert(bci >= block->start_bci() && bci < block->limit_bci(), "block must contain bci.");
 
     answer = block->get_liveness_at(method(), bci);
--- a/src/hotspot/share/compiler/oopMap.cpp	Fri Jul 13 11:21:55 2018 +0800
+++ b/src/hotspot/share/compiler/oopMap.cpp	Thu Jul 12 16:31:28 2018 +0200
@@ -571,14 +571,14 @@
 
 const ImmutableOopMap* ImmutableOopMapSet::find_map_at_offset(int pc_offset) const {
   ImmutableOopMapPair* pairs = get_pairs();
-  ImmutableOopMapPair* last = NULL;
 
-  for (int i = 0; i < _count; ++i) {
+  int i;
+  for (i = 0; i < _count; ++i) {
     if (pairs[i].pc_offset() >= pc_offset) {
-      last = &pairs[i];
       break;
     }
   }
+  ImmutableOopMapPair* last = &pairs[i];
 
   assert(last->pc_offset() == pc_offset, "oopmap not found");
   return last->get_from(this);
--- a/src/hotspot/share/jvmci/jvmciCodeInstaller.cpp	Fri Jul 13 11:21:55 2018 +0800
+++ b/src/hotspot/share/jvmci/jvmciCodeInstaller.cpp	Thu Jul 12 16:31:28 2018 +0200
@@ -236,6 +236,8 @@
 
   JVMCIKlassHandle klass(THREAD);
   oop result = NULL;
+  guarantee(h != NULL,
+            "If DebugInformationRecorder::describe_scope passes NULL oldCount == newCount must hold.");
   if (h->is_klass()) {
     klass = (Klass*) h;
     result = CompilerToVM::get_jvmci_type(klass, CATCH);
--- a/src/hotspot/share/jvmci/jvmciCompilerToVM.cpp	Fri Jul 13 11:21:55 2018 +0800
+++ b/src/hotspot/share/jvmci/jvmciCompilerToVM.cpp	Thu Jul 12 16:31:28 2018 +0200
@@ -349,7 +349,9 @@
     klass = *((Klass**) (intptr_t) (base_address + offset));
   } else {
     THROW_MSG_0(vmSymbols::java_lang_IllegalArgumentException(),
-                err_msg("Unexpected arguments: %s " JLONG_FORMAT " %s", base_object->klass()->external_name(), offset, compressed ? "true" : "false"));
+                err_msg("Unexpected arguments: %s " JLONG_FORMAT " %s",
+                        base_object != NULL ? base_object->klass()->external_name() : "null",
+                        offset, compressed ? "true" : "false"));
   }
   assert (klass == NULL || klass->is_klass(), "invalid read");
   oop result = CompilerToVM::get_jvmci_type(klass, CHECK_NULL);
--- a/src/hotspot/share/opto/arraycopynode.cpp	Fri Jul 13 11:21:55 2018 +0800
+++ b/src/hotspot/share/opto/arraycopynode.cpp	Thu Jul 12 16:31:28 2018 +0200
@@ -659,7 +659,8 @@
   c = bs->step_over_gc_barrier(c);
 
   CallNode* call = NULL;
-  if (c != NULL && c->is_Region()) {
+  guarantee(c != NULL, "step_over_gc_barrier failed, there must be something to step to.");
+  if (c->is_Region()) {
     for (uint i = 1; i < c->req(); i++) {
       if (c->in(i) != NULL) {
         Node* n = c->in(i)->in(0);
--- a/src/hotspot/share/opto/bytecodeInfo.cpp	Fri Jul 13 11:21:55 2018 +0800
+++ b/src/hotspot/share/opto/bytecodeInfo.cpp	Thu Jul 12 16:31:28 2018 +0200
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1998, 2017, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1998, 2018, 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
@@ -520,10 +520,10 @@
                                                caller_bci, inline_msg);
   if (C->print_inlining()) {
     C->print_inlining(callee_method, inline_level(), caller_bci, inline_msg);
-    if (callee_method == NULL) tty->print(" callee not monotonic or profiled");
-    if (Verbose && callee_method) {
+    guarantee(callee_method != NULL, "would crash in post_inlining_event");
+    if (Verbose) {
       const InlineTree *top = this;
-      while( top->caller_tree() != NULL ) { top = top->caller_tree(); }
+      while (top->caller_tree() != NULL) { top = top->caller_tree(); }
       //tty->print("  bcs: %d+%d  invoked: %d", top->count_inline_bcs(), callee_method->code_size(), callee_method->interpreter_invocation_count());
     }
   }
--- a/src/hotspot/share/opto/callnode.cpp	Fri Jul 13 11:21:55 2018 +0800
+++ b/src/hotspot/share/opto/callnode.cpp	Thu Jul 12 16:31:28 2018 +0200
@@ -759,6 +759,7 @@
         }
       }
     }
+    guarantee(dest != NULL, "Call had only one ptr in, broken IR!");
     if (!dest->is_top() && may_modify_arraycopy_helper(phase->type(dest)->is_oopptr(), t_oop, phase)) {
       return true;
     }
--- a/src/hotspot/share/opto/compile.cpp	Fri Jul 13 11:21:55 2018 +0800
+++ b/src/hotspot/share/opto/compile.cpp	Thu Jul 12 16:31:28 2018 +0200
@@ -4049,9 +4049,9 @@
 
 int Compile::ConstantTable::find_offset(Constant& con) const {
   int idx = _constants.find(con);
-  assert(idx != -1, "constant must be in constant table");
+  guarantee(idx != -1, "constant must be in constant table");
   int offset = _constants.at(idx).offset();
-  assert(offset != -1, "constant table not emitted yet?");
+  guarantee(offset != -1, "constant table not emitted yet?");
   return offset;
 }
 
--- a/src/hotspot/share/opto/gcm.cpp	Fri Jul 13 11:21:55 2018 +0800
+++ b/src/hotspot/share/opto/gcm.cpp	Thu Jul 12 16:31:28 2018 +0200
@@ -1263,6 +1263,7 @@
         Node* use = self->fast_out(i);
         LCA = raise_LCA_above_use(LCA, use, self, this);
       }
+      guarantee(LCA != NULL, "There must be a LCA");
     }  // (Hide defs of imax, i from rest of block.)
 
     // Place temps in the block of their use.  This isn't a
--- a/src/hotspot/share/opto/ifnode.cpp	Fri Jul 13 11:21:55 2018 +0800
+++ b/src/hotspot/share/opto/ifnode.cpp	Thu Jul 12 16:31:28 2018 +0200
@@ -387,6 +387,7 @@
     } else {
       assert( 0, "do not know how to handle this guy" );
     }
+    guarantee(proj != NULL, "sanity");
 
     Node *proj_path_data, *proj_path_ctrl;
     if( proj->Opcode() == Op_IfTrue ) {
--- a/src/hotspot/share/opto/indexSet.cpp	Fri Jul 13 11:21:55 2018 +0800
+++ b/src/hotspot/share/opto/indexSet.cpp	Thu Jul 12 16:31:28 2018 +0200
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1998, 2011, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1998, 2018, 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
@@ -319,7 +319,7 @@
   if (_max_blocks <= preallocated_block_list_size) {
     _blocks = _preallocated_block_list;
   } else {
-    _blocks = (IndexSet::BitBlock**) arena()->Amalloc_4(sizeof(IndexSet::BitBlock**) * _max_blocks);
+    _blocks = (IndexSet::BitBlock**) arena()->Amalloc_4(sizeof(IndexSet::BitBlock*) * _max_blocks);
   }
   for (uint i = 0; i < _max_blocks; i++) {
     set_block(i, &_empty_block);
@@ -343,7 +343,7 @@
   if (_max_blocks <= preallocated_block_list_size) {
     _blocks = _preallocated_block_list;
   } else {
-    _blocks = (IndexSet::BitBlock**) arena->Amalloc_4(sizeof(IndexSet::BitBlock**) * _max_blocks);
+    _blocks = (IndexSet::BitBlock**) arena->Amalloc_4(sizeof(IndexSet::BitBlock*) * _max_blocks);
   }
   for (uint i = 0; i < _max_blocks; i++) {
     set_block(i, &_empty_block);
--- a/src/hotspot/share/opto/lcm.cpp	Fri Jul 13 11:21:55 2018 +0800
+++ b/src/hotspot/share/opto/lcm.cpp	Thu Jul 12 16:31:28 2018 +0200
@@ -646,7 +646,7 @@
     }
   } // End of for all ready nodes in worklist
 
-  assert(idx >= 0, "index should be set");
+  guarantee(idx >= 0, "index should be set");
   Node *n = worklist[(uint)idx];      // Get the winner
 
   worklist.map((uint)idx, worklist.pop());     // Compress worklist
--- a/src/hotspot/share/opto/loopPredicate.cpp	Fri Jul 13 11:21:55 2018 +0800
+++ b/src/hotspot/share/opto/loopPredicate.cpp	Thu Jul 12 16:31:28 2018 +0200
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2011, 2017, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2011, 2018, 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
@@ -684,6 +684,7 @@
   Node* max_idx_expr = NULL;
   const TypeInt* idx_type = TypeInt::INT;
   if ((stride > 0) == (scale > 0) == upper) {
+    guarantee(limit != NULL, "sanity");
     if (TraceLoopPredicate) {
       if (limit->is_Con()) {
         predString->print("(%d ", con_limit);
--- a/src/hotspot/share/opto/loopTransform.cpp	Fri Jul 13 11:21:55 2018 +0800
+++ b/src/hotspot/share/opto/loopTransform.cpp	Thu Jul 12 16:31:28 2018 +0200
@@ -768,11 +768,12 @@
   Node *init_n = cl->init_trip();
   Node *limit_n = cl->limit();
   int stride_con = cl->stride_con();
+  if (limit_n == NULL) return false; // We will dereference it below.
+
   // Non-constant bounds.
   // Protect against over-unrolling when init or/and limit are not constant
   // (so that trip_count's init value is maxint) but iv range is known.
-  if (init_n   == NULL || !init_n->is_Con()  ||
-      limit_n  == NULL || !limit_n->is_Con()) {
+  if (init_n == NULL || !init_n->is_Con() || !limit_n->is_Con()) {
     Node* phi = cl->phi();
     if (phi != NULL) {
       assert(phi->is_Phi() && phi->in(0) == _head, "Counted loop should have iv phi.");
--- a/src/hotspot/share/opto/macro.cpp	Fri Jul 13 11:21:55 2018 +0800
+++ b/src/hotspot/share/opto/macro.cpp	Thu Jul 12 16:31:28 2018 +0200
@@ -2154,6 +2154,7 @@
 
   Node* mem  = alock->in(TypeFunc::Memory);
   Node* ctrl = alock->in(TypeFunc::Control);
+  guarantee(ctrl != NULL, "missing control projection, cannot replace_node() with NULL");
 
   extract_call_projections(alock);
   // There are 2 projections from the lock.  The lock node will
@@ -2188,8 +2189,7 @@
   }
 
   // Seach for MemBarReleaseLock node and delete it also.
-  if (alock->is_Unlock() && ctrl != NULL && ctrl->is_Proj() &&
-      ctrl->in(0)->is_MemBar()) {
+  if (alock->is_Unlock() && ctrl->is_Proj() && ctrl->in(0)->is_MemBar()) {
     MemBarNode* membar = ctrl->in(0)->as_MemBar();
     assert(membar->Opcode() == Op_MemBarReleaseLock &&
            mem->is_Proj() && membar == mem->in(0), "");
--- a/src/hotspot/share/opto/memnode.cpp	Fri Jul 13 11:21:55 2018 +0800
+++ b/src/hotspot/share/opto/memnode.cpp	Thu Jul 12 16:31:28 2018 +0200
@@ -370,10 +370,10 @@
 
   if (mem != old_mem) {
     set_req(MemNode::Memory, mem);
-    if (can_reshape && old_mem->outcnt() == 0) {
-        igvn->_worklist.push(old_mem);
+    if (can_reshape && old_mem->outcnt() == 0 && igvn != NULL) {
+      igvn->_worklist.push(old_mem);
     }
-    if (phase->type( mem ) == Type::TOP) return NodeSentinel;
+    if (phase->type(mem) == Type::TOP) return NodeSentinel;
     return this;
   }
 
@@ -825,7 +825,7 @@
     }
     break;
   default:
-    // ShouldNotReachHere(); ???
+    ShouldNotReachHere();
     break;
   }
   assert(load != NULL, "LoadNode should have been created");
--- a/src/hotspot/share/opto/node.hpp	Fri Jul 13 11:21:55 2018 +0800
+++ b/src/hotspot/share/opto/node.hpp	Thu Jul 12 16:31:28 2018 +0200
@@ -1689,9 +1689,10 @@
   int block_idx = (idx >> _log2_node_notes_block_size);
   int grow_by = (block_idx - (arr == NULL? 0: arr->length()));
   if (grow_by >= 0) {
-    if (!can_grow)  return NULL;
+    if (!can_grow) return NULL;
     grow_node_notes(arr, grow_by + 1);
   }
+  if (arr == NULL) return NULL;
   // (Every element of arr is a sub-array of length _node_notes_block_size.)
   return arr->at(block_idx) + (idx & (_node_notes_block_size-1));
 }
--- a/src/hotspot/share/opto/output.cpp	Fri Jul 13 11:21:55 2018 +0800
+++ b/src/hotspot/share/opto/output.cpp	Thu Jul 12 16:31:28 2018 +0200
@@ -1424,7 +1424,7 @@
 
       // See if this instruction has a delay slot
       if (valid_bundle_info(n) && node_bundling(n)->use_unconditional_delay()) {
-        assert(delay_slot != NULL, "expecting delay slot node");
+        guarantee(delay_slot != NULL, "expecting delay slot node");
 
         // Back up 1 instruction
         cb->set_insts_end(cb->insts_end() - Pipeline::instr_unit_size());
--- a/src/hotspot/share/opto/parse1.cpp	Fri Jul 13 11:21:55 2018 +0800
+++ b/src/hotspot/share/opto/parse1.cpp	Thu Jul 12 16:31:28 2018 +0200
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1997, 2017, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2018, 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
@@ -1823,7 +1823,7 @@
       // Instead, wire the new split into a MergeMem on the backedge.
       // The optimizer will sort it out, slicing the phi.
       if (remerge == NULL) {
-        assert(base != NULL, "");
+        guarantee(base != NULL, "");
         assert(base->in(0) != NULL, "should not be xformed away");
         remerge = MergeMemNode::make(base->in(pnum));
         gvn().set_type(remerge, Type::MEMORY);
--- a/src/hotspot/share/opto/reg_split.cpp	Fri Jul 13 11:21:55 2018 +0800
+++ b/src/hotspot/share/opto/reg_split.cpp	Thu Jul 12 16:31:28 2018 +0200
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2000, 2018, 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
@@ -683,7 +683,7 @@
         if( needs_phi ) {
           // create a new phi node and insert it into the block
           // type is taken from left over pointer to a predecessor
-          assert(n3,"No non-NULL reaching DEF for a Phi");
+          guarantee(n3, "No non-NULL reaching DEF for a Phi");
           phi = new PhiNode(b->head(), n3->bottom_type());
           // initialize the Reaches entry for this LRG
           Reachblock[slidx] = phi;
--- a/src/hotspot/share/opto/runtime.cpp	Fri Jul 13 11:21:55 2018 +0800
+++ b/src/hotspot/share/opto/runtime.cpp	Thu Jul 12 16:31:28 2018 +0200
@@ -1608,7 +1608,12 @@
     }
     int bci = jvms->bci();
     if (bci < 0) bci = 0;
-    st.print("%s.%s@%d", m->holder()->name()->as_utf8(), m->name()->as_utf8(), bci);
+    if (m != NULL) {
+      st.print("%s.%s", m->holder()->name()->as_utf8(), m->name()->as_utf8());
+    } else {
+      st.print("no method");
+    }
+    st.print("@%d", bci);
     // To print linenumbers instead of bci use: m->line_number_from_bci(bci)
   }
   NamedCounter* c;
--- a/src/hotspot/share/opto/type.cpp	Fri Jul 13 11:21:55 2018 +0800
+++ b/src/hotspot/share/opto/type.cpp	Thu Jul 12 16:31:28 2018 +0200
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1997, 2017, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2018, 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
@@ -252,17 +252,16 @@
         ciObject* oop_constant = constant.as_object();
         if (oop_constant->is_null_object()) {
           con_type = Type::get_zero_type(T_OBJECT);
-        } else if (require_constant || oop_constant->should_be_constant()) {
+        } else {
+          guarantee(require_constant || oop_constant->should_be_constant(), "con_type must get computed");
           con_type = TypeOopPtr::make_from_constant(oop_constant, require_constant);
-          if (con_type != NULL) {
-            if (Compile::current()->eliminate_boxing() && is_autobox_cache) {
-              con_type = con_type->is_aryptr()->cast_to_autobox_cache(true);
-            }
-            if (stable_dimension > 0) {
-              assert(FoldStableValues, "sanity");
-              assert(!con_type->is_zero_type(), "default value for stable field");
-              con_type = con_type->is_aryptr()->cast_to_stable(true, stable_dimension);
-            }
+          if (Compile::current()->eliminate_boxing() && is_autobox_cache) {
+            con_type = con_type->is_aryptr()->cast_to_autobox_cache(true);
+          }
+          if (stable_dimension > 0) {
+            assert(FoldStableValues, "sanity");
+            assert(!con_type->is_zero_type(), "default value for stable field");
+            con_type = con_type->is_aryptr()->cast_to_stable(true, stable_dimension);
           }
         }
         if (is_narrow_oop) {
--- a/src/hotspot/share/runtime/simpleThresholdPolicy.cpp	Fri Jul 13 11:21:55 2018 +0800
+++ b/src/hotspot/share/runtime/simpleThresholdPolicy.cpp	Thu Jul 12 16:31:28 2018 +0200
@@ -266,8 +266,9 @@
     max_method = max_task->method();
   }
 
-  if (max_task->comp_level() == CompLevel_full_profile && TieredStopAtLevel > CompLevel_full_profile
-      && is_method_profiled(max_method)) {
+  if (max_task != NULL && max_task->comp_level() == CompLevel_full_profile &&
+      TieredStopAtLevel > CompLevel_full_profile &&
+      max_method != NULL && is_method_profiled(max_method)) {
     max_task->set_comp_level(CompLevel_limited_profile);
     if (PrintTieredEvents) {
       print_event(UPDATE_IN_QUEUE, max_method, max_method, max_task->osr_bci(), (CompLevel)max_task->comp_level());