src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/runtime/PerfDataEntry.java
changeset 48166 2659c4fe8ea7
parent 47216 71c04702a3d5
child 48175 babef393c286
equal deleted inserted replaced
48165:4c25d37d8557 48166:2659c4fe8ea7
     1 /*
     1 /*
     2  * Copyright (c) 2004, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 2004, 2017, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.
     7  * published by the Free Software Foundation.
    90 
    90 
    91     public boolean supported() {
    91     public boolean supported() {
    92         return (flags() & 0x1) != 0;
    92         return (flags() & 0x1) != 0;
    93     }
    93     }
    94 
    94 
    95     // NOTE: Keep this in sync with PerfData::Units enum in VM code
    95     private static class PerfDataUnits {
    96     public interface PerfDataUnits {
    96         public static int U_None;
    97         public static final int U_None   = 1;
    97         public static int U_Bytes;
    98         public static final int U_Bytes  = 2;
    98         public static int U_Ticks;
    99         public static final int U_Ticks  = 3;
    99         public static int U_Events;
   100         public static final int U_Events = 4;
   100         public static int U_String;
   101         public static final int U_String = 5;
   101         public static int U_Hertz;
   102         public static final int U_Hertz  = 6;
   102 
       
   103         static {
       
   104             VM.registerVMInitializedObserver(new Observer() {
       
   105                 public void update(Observable o, Object data) {
       
   106                     initialize(VM.getVM().getTypeDataBase());
       
   107                 }
       
   108             });
       
   109         }
       
   110         private static synchronized void initialize(TypeDataBase db) {
       
   111             U_None = db.lookupIntConstant("PerfData::U_None");
       
   112             U_Bytes = db.lookupIntConstant("PerfData::U_Bytes");
       
   113             U_Ticks = db.lookupIntConstant("PerfData::U_Ticks");
       
   114             U_Events = db.lookupIntConstant("PerfData::U_Events");
       
   115             U_String = db.lookupIntConstant("PerfData::U_String");
       
   116             U_Hertz = db.lookupIntConstant("PerfData::U_Hertz");
       
   117         }
   103     }
   118     }
   104 
   119 
   105     // returns one of the constants in PerfDataUnits
   120     // returns one of the constants in PerfDataUnits
   106     public int dataUnits() {
   121     public int dataUnits() {
   107         return (int) dataUnitsField.getValue(addr);
   122         return (int) dataUnitsField.getValue(addr);
   108     }
       
   109 
       
   110     // NOTE: Keep this in sync with PerfData::Variability enum in VM code
       
   111     public interface PerfDataVariability {
       
   112         public static final int V_Constant  = 1;
       
   113         public static final int V_Monotonic = 2;
       
   114         public static final int V_Variable  = 3;
       
   115     }
   123     }
   116 
   124 
   117     // returns one of the constants in PerfDataVariability
   125     // returns one of the constants in PerfDataVariability
   118     public int dataVariability() {
   126     public int dataVariability() {
   119         return (int) dataVariabilityField.getValue(addr);
   127         return (int) dataVariabilityField.getValue(addr);
   449                 break;
   457                 break;
   450             }
   458             }
   451         }
   459         }
   452 
   460 
   453         // add units
   461         // add units
   454         switch (dataUnits()) {
   462         int dataUnitsValue = dataUnits();
   455         case PerfDataUnits.U_None:
   463 
   456             break;
   464         if (dataUnitsValue == PerfDataUnits.U_Bytes) {
   457         case PerfDataUnits.U_Bytes:
       
   458             str += " byte(s)";
   465             str += " byte(s)";
   459             break;
   466         } else if (dataUnitsValue == PerfDataUnits.U_Ticks) {
   460         case PerfDataUnits.U_Ticks:
       
   461             str += " tick(s)";
   467             str += " tick(s)";
   462             break;
   468         } else if (dataUnitsValue == PerfDataUnits.U_Events) {
   463         case PerfDataUnits.U_Events:
       
   464             str += " event(s)";
   469             str += " event(s)";
   465             break;
   470         } else if (dataUnitsValue == PerfDataUnits.U_Hertz) {
   466         case PerfDataUnits.U_String:
       
   467             break;
       
   468         case PerfDataUnits.U_Hertz:
       
   469             str += " Hz";
   471             str += " Hz";
   470             break;
       
   471         }
   472         }
   472 
   473 
   473         return str;
   474         return str;
   474     }
   475     }
   475 
   476