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 sun.evtracing.parser.TraceEventType;
  27 import sun.evtracing.parser.metadata.JavaClass;
  28 import sun.evtracing.parser.metadata.JavaStack;
  29 import sun.evtracing.parser.metadata.MetadataRef;
  30 import sun.evtracing.processing.TraceEventHandler;
  31 
  32 public class ThreadParkBeginEvent extends GlobalSequenceOrderedEvent {
  33 
  34         public static final TraceEventType EVENT_TYPE = TraceEventType.ThreadParkBegin;
  35 
  36         public static ThreadParkBeginEvent parse(TraceReader reader, long thread) {
  37                 TraceEventType eventType = reader.readEventType();
  38                 assert eventType == EVENT_TYPE;
  39                 long timestamp = reader.readTimestamp();
  40                 long sequenceNumber = reader.readSequenceNumber();
  41                 int blockerObject = reader.readObject();
  42                 MetadataRef<JavaClass> clazz = reader.readClass();
  43                 MetadataRef<JavaStack> stack = reader.readStack();
  44                 int nestingLevel = reader.readUnsignedByte();
  45                 boolean isAbsolute = reader.readBoolean();
  46                 long parkTime = reader.readDuration();
  47                 return new ThreadParkBeginEvent(thread, timestamp, sequenceNumber, blockerObject, clazz, stack, nestingLevel, isAbsolute, parkTime);
  48         }
  49 
  50         private final int blockerObject;
  51         private final MetadataRef<JavaClass> clazz;
  52         private final MetadataRef<JavaStack> stack;
  53         private final int nestingLevel;
  54         private final boolean isAbsolute;
  55         private final long parkTime;
  56 
  57         protected ThreadParkBeginEvent(long thread, long timestamp, long sequenceNumber, int blockerObject, MetadataRef<JavaClass> clazz, MetadataRef<JavaStack> stack, int nestingLevel, boolean isAbsolute, long parkTime) {
  58                 super(thread, timestamp, sequenceNumber);
  59                 this.blockerObject = blockerObject;
  60                 this.clazz = clazz;
  61                 this.stack = stack;
  62                 this.nestingLevel = nestingLevel;
  63                 this.isAbsolute = isAbsolute;
  64                 this.parkTime = parkTime;
  65         }
  66 
  67         @Override
  68         public TraceEventType type() {
  69                 return EVENT_TYPE;
  70         }
  71 
  72         public int blockerObject() {
  73                 return blockerObject;
  74         }
  75 
  76         public MetadataRef<JavaClass> clazz() {
  77                 return clazz;
  78         }
  79 
  80         public MetadataRef<JavaStack> stack() {
  81                 return stack;
  82         }
  83 
  84         public int nestingLevel() {
  85                 return nestingLevel;
  86         }
  87 
  88         public boolean isAbsolute() {
  89                 return isAbsolute;
  90         }
  91 
  92         public long parkTime() {
  93                 return parkTime;
  94         }
  95 
  96         @Override
  97         public void accept(TraceEventHandler handler) {
  98                 handler.threadParkBegin(this);
  99         }
 100 }