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.processing.statistics.metadata; 25 26 import java.util.Arrays; 27 import sun.evtracing.parser.metadata.JavaClass; 28 29 public class JavaObjectArrayStack extends JavaObjectStack { 30 31 private final JavaObject[] objects; 32 33 public JavaObjectArrayStack(JavaObject... objects) { 34 this.objects = objects; 35 } 36 37 public JavaObjectArrayStack(int size) { 38 this.objects = new JavaObject[size]; 39 } 40 41 @Override 42 public JavaObject top() { 43 JavaObject top = objects[objects.length - 1]; 44 assert top != null; 45 return top; 46 } 47 48 @Override 49 public JavaObject[] objects() { 50 assert Arrays.stream(objects).allMatch(o -> o != null); 51 return objects; 52 } 53 54 @Override 55 public void setObject(int number, JavaObject obj) { 56 assert number < objects.length; 57 assert objects[number] == null; 58 objects[number] = obj; 59 } 60 61 @Override 62 public JavaClassStack getClassStack() { 63 JavaClass[] classes = new JavaClass[objects.length]; 64 for (int i = 0; i < objects.length; i++) { 65 classes[i] = objects[i].clazz(); 66 } 67 return new JavaClassStack(classes); 68 } 69 70 }