001/*
002 * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
003 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004 *
005 * This code is free software; you can redistribute it and/or modify it
006 * under the terms of the GNU General Public License version 2 only, as
007 * published by the Free Software Foundation.
008 *
009 * This code is distributed in the hope that it will be useful, but WITHOUT
010 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
011 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
012 * version 2 for more details (a copy is included in the LICENSE file that
013 * accompanied this code).
014 *
015 * You should have received a copy of the GNU General Public License version
016 * 2 along with this work; if not, write to the Free Software Foundation,
017 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
018 *
019 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
020 * or visit www.oracle.com if you need additional information or have any
021 * questions.
022 */
023package jdk.internal.jvmci.meta;
024
025/**
026 * An implementation of {@link ProfilingInfo} that can used in the absence of real profile
027 * information.
028 */
029public final class DefaultProfilingInfo implements ProfilingInfo {
030
031    private static final ProfilingInfo[] NO_PROFILING_INFO = new ProfilingInfo[]{new DefaultProfilingInfo(TriState.TRUE), new DefaultProfilingInfo(TriState.FALSE),
032                    new DefaultProfilingInfo(TriState.UNKNOWN)};
033
034    private final TriState exceptionSeen;
035
036    DefaultProfilingInfo(TriState exceptionSeen) {
037        this.exceptionSeen = exceptionSeen;
038    }
039
040    @Override
041    public int getCodeSize() {
042        return 0;
043    }
044
045    @Override
046    public JavaTypeProfile getTypeProfile(int bci) {
047        return null;
048    }
049
050    @Override
051    public JavaMethodProfile getMethodProfile(int bci) {
052        return null;
053    }
054
055    @Override
056    public double getBranchTakenProbability(int bci) {
057        return -1;
058    }
059
060    @Override
061    public double[] getSwitchProbabilities(int bci) {
062        return null;
063    }
064
065    @Override
066    public TriState getExceptionSeen(int bci) {
067        return exceptionSeen;
068    }
069
070    @Override
071    public TriState getNullSeen(int bci) {
072        return TriState.UNKNOWN;
073    }
074
075    @Override
076    public int getExecutionCount(int bci) {
077        return -1;
078    }
079
080    public static ProfilingInfo get(TriState exceptionSeen) {
081        return NO_PROFILING_INFO[exceptionSeen.ordinal()];
082    }
083
084    @Override
085    public int getDeoptimizationCount(DeoptimizationReason reason) {
086        return 0;
087    }
088
089    @Override
090    public boolean isMature() {
091        return false;
092    }
093
094    @Override
095    public String toString() {
096        return "BaseProfilingInfo<" + this.toString(null, "; ") + ">";
097    }
098
099    public void setMature() {
100        // Do nothing
101    }
102
103    public boolean setCompilerIRSize(Class<?> irType, int nodeCount) {
104        return false;
105    }
106
107    public int getCompilerIRSize(Class<?> irType) {
108        return -1;
109    }
110}