Mercurial > hg > truffle
view graal/com.oracle.graal.api.meta/src/com/oracle/graal/api/meta/AbstractJavaProfile.java @ 12426:492c428f6035
made use of substitution when deriving a new Providers object
author | Doug Simon <doug.simon@oracle.com> |
---|---|
date | Mon, 14 Oct 2013 11:24:04 +0200 |
parents | 89cbd0119dc5 |
children | 8c4a3d9308a7 |
line wrap: on
line source
/* * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ package com.oracle.graal.api.meta; import java.io.*; /** * This object holds probability information for a set of items that were profiled at a specific * BCI. The precision of the supplied values may vary, but a runtime that provides this information * should be aware that it will be used to guide performance-critical decisions like speculative * inlining, etc. * * @param <T> a subclass of AbstractProfiledItem * @param <U> the class of the items that are profiled at the specific BCI and for which * probabilities are stored. E.g., a ResolvedJavaType or a ResolvedJavaMethod. */ public abstract class AbstractJavaProfile<T extends AbstractProfiledItem<U>, U> implements Serializable { private static final long serialVersionUID = 5493379044459116749L; private final double notRecordedProbability; private final T[] pitems; public AbstractJavaProfile(double notRecordedProbability, T[] pitems) { this.pitems = pitems; assert notRecordedProbability != Double.NaN; this.notRecordedProbability = notRecordedProbability; assert isSorted(); } /** * Determines if an array of profiled items are sorted in descending order of their * probabilities. */ private boolean isSorted() { for (int i = 1; i < pitems.length; i++) { if (pitems[i - 1].getProbability() < pitems[i].getProbability()) { return false; } } return true; } /** * Returns the estimated probability of all types that could not be recorded due to profiling * limitations. * * @return double value >= 0.0 and <= 1.0 */ public double getNotRecordedProbability() { return notRecordedProbability; } protected T[] getItems() { return pitems; } /** * Searches for an entry of a given resolved Java type. * * @param type the type for which an entry should be searched * @return the entry or null if no entry for this type can be found */ public T findEntry(ResolvedJavaType type) { if (pitems != null) { for (T pt : pitems) { if (pt.getItem() == type) { return pt; } } } return null; } @Override public String toString() { StringBuilder builder = new StringBuilder(); builder.append(this.getClass().getName()); builder.append("["); if (pitems != null) { for (T pt : pitems) { builder.append(pt.toString()); builder.append(", "); } } builder.append(this.notRecordedProbability); builder.append("]"); return builder.toString(); } public boolean isIncluded(U item) { if (this.getNotRecordedProbability() > 0.0) { return true; } else { for (int i = 0; i < getItems().length; i++) { T pitem = getItems()[i]; U curType = pitem.getItem(); if (curType == item) { return true; } } } return false; } @Override public boolean equals(Object other) { if (other == this) { return true; } if (getClass() == other.getClass()) { AbstractJavaProfile javaTypeProfile = (AbstractJavaProfile) other; if (javaTypeProfile.notRecordedProbability != notRecordedProbability) { return false; } if (javaTypeProfile.pitems.length != pitems.length) { return false; } for (int i = 0; i < pitems.length; ++i) { if (!pitems[i].equals(javaTypeProfile.pitems[i])) { return false; } } return true; } return false; } @Override public int hashCode() { return (int) Double.doubleToLongBits(notRecordedProbability) + pitems.length * 13; } }