< prev index next >

src/hotspot/share/opto/output.cpp

Print this page
rev 54763 : 8213084: Rework and enhance Print[Opto]Assembly output
Reviewed-by:

@@ -1,7 +1,7 @@
 /*
- * Copyright (c) 1998, 2018, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1998, 2019, 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.

@@ -1104,16 +1104,21 @@
   uint* jmp_size   = NEW_RESOURCE_ARRAY(uint,nblocks);
   uint* jmp_rule   = NEW_RESOURCE_ARRAY(uint,nblocks);
 #endif
 
   // Create an array of unused labels, one for each basic block, if printing is enabled
-#ifndef PRODUCT
+#if defined(SUPPORT_OPTO_ASSEMBLY)
   int *node_offsets      = NULL;
   uint node_offset_limit = unique();
 
-  if (print_assembly())
+  if (print_assembly()) {
     node_offsets         = NEW_RESOURCE_ARRAY(int, node_offset_limit);
+  }
+  if (node_offsets != NULL) {
+    // We need to initialize. Unused array elements may contain garbage and mess up PrintOptoAssembly.
+    memset(node_offsets, 0, node_offset_limit*sizeof(int));
+  }
 #endif
 
   NonSafepointEmitter non_safepoints(this);  // emit non-safepoints lazily
 
   // Emit the constant table.

@@ -1379,13 +1384,14 @@
         C->record_failure("CodeCache is full");
         return;
       }
 
       // Save the offset for the listing
-#ifndef PRODUCT
-      if (node_offsets && n->_idx < node_offset_limit)
+#if defined(SUPPORT_OPTO_ASSEMBLY)
+      if ((node_offsets != NULL) && (n->_idx < node_offset_limit)) {
         node_offsets[n->_idx] = cb->insts_size();
+      }
 #endif
 
       // "Normal" instruction case
       DEBUG_ONLY( uint instr_offset = cb->insts_size(); )
       n->emit(*cb, _regalloc);

@@ -1428,13 +1434,14 @@
 
         // Back up 1 instruction
         cb->set_insts_end(cb->insts_end() - Pipeline::instr_unit_size());
 
         // Save the offset for the listing
-#ifndef PRODUCT
-        if (node_offsets && delay_slot->_idx < node_offset_limit)
+#if defined(SUPPORT_OPTO_ASSEMBLY)
+        if ((node_offsets != NULL) && (delay_slot->_idx < node_offset_limit)) {
           node_offsets[delay_slot->_idx] = cb->insts_size();
+        }
 #endif
 
         // Support a SafePoint in the delay slot
         if (delay_slot->is_MachSafePoint()) {
           MachNode *mach = delay_slot->as_Mach();

@@ -1539,11 +1546,18 @@
   if ((cb->blob() == NULL) || (!CompileBroker::should_compile_new_jobs())) {
     C->record_failure("CodeCache is full");
     return;
   }
 
-#ifndef PRODUCT
+#if defined(SUPPORT_ABSTRACT_ASSEMBLY) || defined(SUPPORT_ASSEMBLY) || defined(SUPPORT_OPTO_ASSEMBLY)
+  if (print_assembly()) {
+    tty->cr();
+    tty->print_cr("============================= C2-compiled nmethod ==============================");
+  }
+#endif
+
+#if defined(SUPPORT_OPTO_ASSEMBLY)
   // Dump the assembly code, including basic-block numbers
   if (print_assembly()) {
     ttyLocker ttyl;  // keep the following output all in one block
     if (!VMThread::should_terminate()) {  // test this under the tty lock
       // This output goes directly to the tty, not the compiler log.

@@ -1553,26 +1567,29 @@
         xtty->head("opto_assembly compile_id='%d'%s", compile_id(),
                    is_osr_compilation()    ? " compile_kind='osr'" :
                    "");
       }
       if (method() != NULL) {
+        tty->print_cr("----------------------------------- MetaData -----------------------------------");
         method()->print_metadata();
       } else if (stub_name() != NULL) {
-        tty->print_cr("Generating RuntimeStub - %s", stub_name());
+        tty->print_cr("----------------------------- RuntimeStub %s -------------------------------", stub_name());
       }
+      tty->cr();
+      tty->print_cr("--------------------------------- OptoAssembly ---------------------------------");
       dump_asm(node_offsets, node_offset_limit);
+      tty->print_cr("--------------------------------------------------------------------------------");
       if (xtty != NULL) {
         // print_metadata and dump_asm above may safepoint which makes us loose the ttylock.
         // Retake lock too make sure the end tag is coherent, and that xmlStream->pop_tag is done
         // thread safe
         ttyLocker ttyl2;
         xtty->tail("opto_assembly");
       }
     }
   }
 #endif
-
 }
 
 void Compile::FillExceptionTables(uint cnt, uint *call_returns, uint *inct_starts, Label *blk_labels) {
   _inc_table.set_size(cnt);
 
< prev index next >