index += VM_HardwarePerformanceMonitors.SIZE_OF_INT;
index = index.add(BYTES_IN_INT);
  private void tracing(int tid, int global_tid, long startOfWallTime,                        long endOfWallTime, HPM_counters counters, boolean threadSwitch)   {    //-#if RVM_WITH_HPM    // which buffer to use    if (! processCallbacksFromConsumer()) return;    if (! pickBuffer(VM_HardwarePerformanceMonitors.getRecordSize())) return;    // buffer != null only if active==true    //BEGIN HRM    int callee_MID;    int caller_MID;    if (cmidAvailable) {      if (callee_CMID<1 || callee_CMID>=VM_CompiledMethods.numCompiledMethods()) {        callee_MID = CMID_OUT_OF_BOUNDS_MID;        VM.sysWriteln("***VM_HPM.tracing() CALLEE_CMID_OUT_OF_BOUNDS_MID*** ",callee_CMID);        VM.sysExit(-1);      } else {        final VM_CompiledMethod cm1 = VM_CompiledMethods.getCompiledMethod(callee_CMID);        if (cm1==null) {          callee_MID = CMID_WITHOUT_COMPILED_METHOD_MID;          VM.sysWriteln("***VM_HPM.tracing() CALLEE_CMID_WITHOUT_COMPILED_METHOD_MID*** ",callee_CMID);          VM.sysExit(-1);        } else {          final VM_Method m1 = cm1.getMethod();          if (m1==null) {            callee_MID = COMPILED_METHOD_WITHOUT_METHOD_MID;            VM.sysWriteln("***VM_HPM.tracing() CALLEE_CMID_WITHOUT_METHOD_MID*** ",callee_CMID);            VM.sysExit(-1);          } else {            callee_MID = m1.getId();            /**            VM.sysWrite("m1: ["); VM.sysWrite(m1.getId()); VM.sysWrite("] ");            VM.sysWrite(m1.getDeclaringClass().getDescriptor());            VM.sysWrite(m1.getName()); VM.sysWrite(m1.getDescriptor()); VM.sysWriteln();            **/          }        }      }      if (caller_CMID<1 || caller_CMID>=VM_CompiledMethods.numCompiledMethods()) {        caller_MID = CMID_OUT_OF_BOUNDS_MID;        VM.sysWriteln("***VM_HPM.tracing() CALLER_CMID_OUT_OF_BOUNDS_MID*** ",caller_CMID);        VM.sysExit(-1);      } else {        final VM_CompiledMethod cm2 = VM_CompiledMethods.getCompiledMethod(caller_CMID);        if (cm2==null) {          caller_MID = CMID_WITHOUT_COMPILED_METHOD_MID;          VM.sysWriteln("***VM_HPM.tracing() CALLER_CMID_WITHOUT_COMPILED_METHOD_MID*** ",caller_CMID);          VM.sysExit(-1);        } else {          final VM_Method m2 = cm2.getMethod();          if (m2==null) {            caller_MID = COMPILED_METHOD_WITHOUT_METHOD_MID;            VM.sysWriteln("***VM_HPM.tracing() CALLER_CMID_WITHOUT_METHOD_MID*** ",caller_CMID);            VM.sysExit(-1);          } else {            caller_MID = m2.getId();            /**            VM.sysWrite("m2: ["); VM.sysWrite(m2.getId()); VM.sysWrite("] ");            VM.sysWrite(m2.getDeclaringClass().getDescriptor());            VM.sysWrite(m2.getName()); VM.sysWrite(m2.getDescriptor()); VM.sysWriteln();            **/          }        }      }      //VM_Thread.dumpCallStack();      cmidAvailableCount++;      cmidAvailable = false;    } else {      cmidUnavailableCount++;      VM.sysWrite("***VM_HPM.tracing() cmidAvailable == false***");      VM.sysWrite("cmidAvailableCount:   ");      VM.sysWriteln(cmidAvailableCount);      VM.sysWrite("cmidUnavailableCount:   ");      VM.sysWriteln(cmidUnavailableCount);      //VM.sysWriteln("cmid NOT available");      VM_Thread.dumpCallStack();      callee_MID = UNAVAILABLE_MID;      caller_MID = UNAVAILABLE_MID;    }    //END HRM    int thread_switch = (threadSwitch==true?1:0);    int encoding = (tid  << 16) + (buffer_code << 15) + (thread_switch << 14) +                    (vpid <<  4) + TRACE_FORMAT;    if(VM_HardwarePerformanceMonitors.verbose>=5 || VM_HardwarePerformanceMonitors.trace_verbose == vpid) {      if (threadSwitch) VM.sysWrite(" ");      else              VM.sysWrite("*");      VM.sysWrite(index,": ");      VM.sysWrite(TRACE_FORMAT);      VM.sysWrite(" BC ",buffer_code);      VM.sysWrite(" PID ", vpid);        //      VM.sysWrite(" ("); VM.sysWriteHex(encoding); VM.sysWrite(")");      VM.sysWrite(" GTID "); if (global_tid < 10) VM.sysWrite(" ");VM.sysWrite(global_tid);      VM.sysWrite( " TID "); if (       tid < 10) VM.sysWrite(" ");VM.sysWrite(       tid);      VM.sysWrite(" SWT " ); VM.sysWriteLong(startOfWallTime);      VM.sysWrite(" EWT " ); VM.sysWriteLong(endOfWallTime);      //BEGIN HRM      VM.sysWrite(" CALLEE ", callee_MID);      VM.sysWrite(" CALLER ", caller_MID);      //END HRM      if(n_values > 5) VM.sysWrite("\n  ");    }    if (buffer != null) { // write record header      n_records++;      VM_Magic.setIntAtOffset( buffer, index, encoding);        // encoding      index += VM_HardwarePerformanceMonitors.SIZE_OF_INT;      VM_Magic.setIntAtOffset( buffer, index, global_tid);      // globally unique tid        index += VM_HardwarePerformanceMonitors.SIZE_OF_INT;      VM_Magic.setLongAtOffset(buffer, index, startOfWallTime); // start of global time      index += VM_HardwarePerformanceMonitors.SIZE_OF_LONG;      VM_Magic.setLongAtOffset(buffer, index,   endOfWallTime); // end   of global time      index += VM_HardwarePerformanceMonitors.SIZE_OF_LONG;      //BEGIN HRM      VM_Magic.setIntAtOffset( buffer, index, callee_MID);      // callee MID      index += VM_HardwarePerformanceMonitors.SIZE_OF_INT;      VM_Magic.setIntAtOffset( buffer, index, caller_MID);      // caller MID      index += VM_HardwarePerformanceMonitors.SIZE_OF_INT;      //END HRM    }    for(int i=1; i<n_values; i++) {      long value = counters.counters[i];      if(VM_HardwarePerformanceMonitors.verbose>=5 || VM_HardwarePerformanceMonitors.trace_verbose == vpid) {        VM.sysWrite(" ",i,": ");VM.sysWriteLong(value);       }      if (buffer != null) { // write HPM counter values        VM_Magic.setLongAtOffset(buffer, index, value);                   index += VM_HardwarePerformanceMonitors.SIZE_OF_LONG;      }    }    if (VM_HardwarePerformanceMonitors.verbose>=5 ||         VM_HardwarePerformanceMonitors.trace_verbose == vpid) {      VM.sysWriteln();    }    updateBufferIndex();    //-#endif  }