Mercurial > hg > graal-compiler
view graal/com.oracle.max.cri/src/com/oracle/max/cri/ri/RiTypeProfile.java @ 5470:044502e7b5a4
Small clean up on RiRuntime.
author | Thomas Wuerthinger <thomas.wuerthinger@oracle.com> |
---|---|
date | Fri, 01 Jun 2012 16:31:49 +0200 |
parents | 2e9a5365dfb0 |
children |
line wrap: on
line source
/* * Copyright (c) 2011, 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.max.cri.ri; import java.io.*; /** * This profile object represents the type profile 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. */ public final class RiTypeProfile implements Serializable { private static final long serialVersionUID = -6877016333706838441L; /** * A profiled type that has a probability. Profiled types are naturally sorted in * descending order of their probabilities. */ public static class ProfiledType implements Comparable<ProfiledType>, Serializable { private static final long serialVersionUID = 7838575753661305744L; public final RiResolvedType type; public final double probability; public ProfiledType(RiResolvedType type, double probability) { assert type != null; assert probability >= 0.0D && probability <= 1.0D; this.type = type; this.probability = probability; } @Override public int compareTo(ProfiledType o) { if (probability > o.probability) { return -1; } else if (probability < o.probability) { return 1; } return 0; } } private final double notRecordedProbability; private final ProfiledType[] ptypes; /** * Determines if an array of profiled types are sorted in descending order of their probabilities. */ public static boolean isSorted(ProfiledType[] ptypes) { for (int i = 1; i < ptypes.length; i++) { if (ptypes[i - 1].probability < ptypes[i].probability) { return false; } } return true; } public RiTypeProfile(double notRecordedProbability, ProfiledType... ptypes) { this.ptypes = ptypes; this.notRecordedProbability = notRecordedProbability; assert isSorted(ptypes); } /** * 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; } /** * A list of types for which the runtime has recorded probability information. */ public ProfiledType[] getTypes() { return ptypes; } }