The following code shows how to organize debug printing with minimal impact on the loaded system

#include <syslog.h>
#include <stdarg.h>
#include <stdlib.h>

static void print_at(const char *srcfile, int line, const char *format, ...) {
  va_list ap;
  const char *envvar="JAVA_SHOULD_PRINT_AT";
  static int requested_line = -1;

  if (requested_line == -1) {
    const char *should_print = getenv(envvar);
    requested_line = (should_print != NULL) ? atoi(should_print) : 0;
    openlog("javadebug", LOG_PID, LOG_UUCP);
  }

  if (requested_line == line) {
     va_start(ap, format);
     vsyslog(LOG_DEBUG, format, ap);
     va_end(ap);
  }
}

It's not always obvious what assembly will be generated after expanding all the macros of the HotSpot meta-assembly system. The following code shows how to print the actual code generated by HotSpot.

// #define DMS_DEBUG
#ifdef DMS_DEBUG
address barrier_start = masm->code()->insts_end();
#endif
 __ block_comment("nmethod_barrier begin");
 __ ldr_label(tmp0, guard);
...
 __ bind(skip);
 __ block_comment("nmethod_barrier end"); 

#ifdef DMS_DEBUG 
address barrier_end = masm->code()->insts_end(); 
tty->print_cr("DMS: barier %p %p bytes: %d", barrier_start, barrier_end, barrier_end - barrier_start); 

//  masm->code()->print(); 
masm->code()->decode(); 
#endif