1 /*
   2  * Copyright (c) 2014, 2015, Dynatrace and/or its affiliates. All rights reserved.
   3  * 
   4  * This file is part of the Lock Contention Tracing Subsystem for the HotSpot
   5  * Virtual Machine, which is developed at Christian Doppler Laboratory on
   6  * Monitoring and Evolution of Very-Large-Scale Software Systems. Please
   7  * contact us at <http://mevss.jku.at/> if you need additional information
   8  * or have any questions.
   9  *
  10  * This code is free software; you can redistribute it and/or modify it
  11  * under the terms of the GNU General Public License version 2 only, as
  12  * published by the Free Software Foundation.
  13  *
  14  * This code is distributed in the hope that it will be useful, but WITHOUT
  15  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  16  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  17  * version 2 for more details (a copy is included in the LICENSE file that
  18  * accompanied this code).
  19  *
  20  * You should have received a copy of the GNU General Public License version
  21  * 2 along with this work. If not, see <http://www.gnu.org/licenses/>.
  22  *
  23  */ 
  24 package sun.evtracing.parser;
  25 
  26 import java.nio.ByteBuffer;
  27 import java.util.EnumSet;
  28 
  29 import sun.evtracing.parser.TraceEventType;
  30 import sun.evtracing.parser.metadata.JavaClass;
  31 import sun.evtracing.parser.metadata.JavaMethod;
  32 import sun.evtracing.parser.metadata.JavaStack;
  33 import sun.evtracing.parser.metadata.JavaThread;
  34 import sun.evtracing.parser.metadata.MetadataRef;
  35 
  36 public class TraceReader extends TraceReaderBase {
  37         static {
  38                 assert TraceEventType.values().length <= TraceReader.UNSIGNED_BYTE_MAX_VALUE;
  39                 assert ParkReturnCode.values().length <= UNSIGNED_BYTE_MAX_VALUE;
  40                 assert SafepointReason.values().length <= UNSIGNED_BYTE_MAX_VALUE;
  41         }
  42 
  43         public TraceReader(ByteBuffer buffer) {
  44                 super(buffer);
  45         }
  46 
  47         // A lot less useful without typedefs, but we don't want to wrap all those
  48         // values in heap objects
  49 
  50         public TraceEventType readEventType() {
  51                 return TraceEventType.fromOrdinal(readByte());
  52         }
  53 
  54         public long readTimestamp() {
  55                 return readLong();
  56         }
  57 
  58         public long readDuration() {
  59                 return readLong();
  60         }
  61 
  62         public long readThreadId() {
  63                 return readLong();
  64         }
  65 
  66         public MetadataRef<JavaThread> readThread() {
  67                 return new MetadataRef<>(readThreadId());
  68         }
  69 
  70         public ThreadState readThreadState() {
  71                 return ThreadState.fromFlags(readInt());
  72         }
  73 
  74         public int readObject() {
  75                 return readInt();
  76         }
  77 
  78         public long readSequenceNumber() {
  79                 return readLong();
  80         }
  81 
  82         public long readMetadataVersion() {
  83                 return readLong();
  84         }
  85 
  86         public long readClassId() {
  87                 return readLong();
  88         }
  89 
  90         public MetadataRef<JavaClass> readClass() {
  91                 return new MetadataRef<>(readClassId());
  92         }
  93 
  94         public long readClassLoader() {
  95                 return readLong();
  96         }
  97 
  98         public long readMethodId() {
  99                 return readLong();
 100         }
 101 
 102         public MetadataRef<JavaMethod> readMethod() {
 103                 return new MetadataRef<>(readMethodId());
 104         }
 105 
 106         public int readBytecodeIndex() {
 107                 return readInt();
 108         }
 109 
 110         public long readStackId() {
 111                 return readLong();
 112         }
 113 
 114         public MetadataRef<JavaStack> readStack() {
 115                 return new MetadataRef<>(readStackId());
 116         }
 117 
 118         public ParkReturnCode readParkReturnCode() {
 119                 return ParkReturnCode.fromOrdinal(readUnsignedByte());
 120         }
 121 
 122         public SafepointReason readSafepointReason() {
 123                 return SafepointReason.fromOrdinal(readUnsignedByte());
 124         }
 125 
 126         public long readMonitor() {
 127                 return readLong();
 128         }
 129 
 130         public MonitorEnterWait readMonitorEnterWait() {
 131                 return MonitorEnterWait.fromOrdinal(readUnsignedByte());
 132         }
 133 
 134         public EnumSet<MonitorEnteredFlags> readMonitorEnteredFlags() {
 135                 return MonitorEnteredFlags.fromBits(readUnsignedByte());
 136         }
 137 }