Path: blob/master/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/utilities/IntervalNode.java
41161 views
/*1* Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*22*/2324package sun.jvm.hotspot.utilities;2526/** Derived from the example in Section 15.3 of CLR. */2728import java.util.Comparator;2930public class IntervalNode extends RBNode {31private Interval interval;32private Comparator<Object> endpointComparator;33private Object minEndpoint;34private Object maxEndpoint;3536public IntervalNode(Interval interval, Comparator<Object> endpointComparator, Object data) {37super(data);38this.interval = interval;39this.endpointComparator = endpointComparator;40}4142public void copyFrom(RBNode arg) {43IntervalNode argNode = (IntervalNode) arg;44this.interval = argNode.interval;45}4647public Interval getInterval() {48return interval;49}5051public Object getMinEndpoint() {52return minEndpoint;53}5455public Object getMaxEndpoint() {56return maxEndpoint;57}5859public boolean update() {60Object newMaxEndpoint = computeMaxEndpoint();61Object newMinEndpoint = computeMinEndpoint();6263if ((maxEndpoint != newMaxEndpoint) || (minEndpoint != newMinEndpoint)) {64maxEndpoint = newMaxEndpoint;65minEndpoint = newMinEndpoint;66return true;67}6869return false;70}7172// Computes maximum endpoint without setting it in this node73public Object computeMinEndpoint() {74IntervalNode left = (IntervalNode) getLeft();75if (left != null) {76return left.getMinEndpoint();77}78return interval.getLowEndpoint();79}8081// Computes maximum endpoint without setting it in this node82public Object computeMaxEndpoint() {83Object curMax = interval.getHighEndpoint();84if (getLeft() != null) {85IntervalNode left = (IntervalNode) getLeft();86if (endpointComparator.compare(left.getMaxEndpoint(), curMax) > 0) {87curMax = left.getMaxEndpoint();88}89}9091if (getRight() != null) {92IntervalNode right = (IntervalNode) getRight();93if (endpointComparator.compare(right.getMaxEndpoint(), curMax) > 0) {94curMax = right.getMaxEndpoint();95}96}97return curMax;98}99100public String toString() {101String res = interval.toString();102Object d = getData();103if (d != null) {104res += " " + d;105}106return res;107}108}109110111