src/jdk/nashorn/internal/runtime/SpecializedMethodChooser.java

changeset 137
e15806b9d716
parent 136
c54e218333be
child 138
60684aeba89c
     1.1 --- a/src/jdk/nashorn/internal/runtime/SpecializedMethodChooser.java	Tue Mar 12 18:12:42 2013 +0530
     1.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.3 @@ -1,99 +0,0 @@
     1.4 -/*
     1.5 - * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
     1.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     1.7 - *
     1.8 - * This code is free software; you can redistribute it and/or modify it
     1.9 - * under the terms of the GNU General Public License version 2 only, as
    1.10 - * published by the Free Software Foundation.  Oracle designates this
    1.11 - * particular file as subject to the "Classpath" exception as provided
    1.12 - * by Oracle in the LICENSE file that accompanied this code.
    1.13 - *
    1.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
    1.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    1.16 - * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    1.17 - * version 2 for more details (a copy is included in the LICENSE file that
    1.18 - * accompanied this code).
    1.19 - *
    1.20 - * You should have received a copy of the GNU General Public License version
    1.21 - * 2 along with this work; if not, write to the Free Software Foundation,
    1.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    1.23 - *
    1.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    1.25 - * or visit www.oracle.com if you need additional information or have any
    1.26 - * questions.
    1.27 - */
    1.28 -
    1.29 -package jdk.nashorn.internal.runtime;
    1.30 -
    1.31 -import java.lang.invoke.MethodHandle;
    1.32 -import java.lang.invoke.MethodType;
    1.33 -import jdk.nashorn.internal.codegen.types.Type;
    1.34 -import jdk.nashorn.internal.runtime.options.Options;
    1.35 -
    1.36 -class SpecializedMethodChooser {
    1.37 -    /** Should specialized function and specialized constructors for the builtin be used if available? */
    1.38 -    private static final boolean DISABLE_SPECIALIZATION = Options.getBooleanProperty("nashorn.scriptfunction.specialization.disable");
    1.39 -
    1.40 -    static MethodHandle candidateWithLowestWeight(final MethodType descType, final MethodHandle initialCandidate, final MethodHandle[] specs) {
    1.41 -        if (DISABLE_SPECIALIZATION || specs == null) {
    1.42 -            return initialCandidate;
    1.43 -        }
    1.44 -
    1.45 -        int          minimumWeight = Integer.MAX_VALUE;
    1.46 -        MethodHandle candidate     = initialCandidate;
    1.47 -
    1.48 -        for (final MethodHandle spec : specs) {
    1.49 -            final MethodType specType = spec.type();
    1.50 -
    1.51 -            if (!typeCompatible(descType, specType)) {
    1.52 -                continue;
    1.53 -            }
    1.54 -
    1.55 -            //return type is ok. we want a wider or equal one for our callsite.
    1.56 -            final int specWeight = weigh(specType);
    1.57 -            if (specWeight < minimumWeight) {
    1.58 -                candidate = spec;
    1.59 -                minimumWeight = specWeight;
    1.60 -            }
    1.61 -        }
    1.62 -
    1.63 -        return candidate;
    1.64 -    }
    1.65 -
    1.66 -    private static boolean typeCompatible(final MethodType desc, final MethodType spec) {
    1.67 -        //spec must fit in desc
    1.68 -        final Class<?>[] dparray = desc.parameterArray();
    1.69 -        final Class<?>[] sparray = spec.parameterArray();
    1.70 -
    1.71 -        if (dparray.length != sparray.length) {
    1.72 -            return false;
    1.73 -        }
    1.74 -
    1.75 -        for (int i = 0; i < dparray.length; i++) {
    1.76 -            final Type dp = Type.typeFor(dparray[i]);
    1.77 -            final Type sp = Type.typeFor(sparray[i]);
    1.78 -
    1.79 -            if (dp.isBoolean()) {
    1.80 -                return false; //don't specialize on booleans, we have the "true" vs int 1 ambiguity in resolution
    1.81 -            }
    1.82 -
    1.83 -            //specialization arguments must be at least as wide as dp, if not wider
    1.84 -            if (Type.widest(dp, sp) != sp) {
    1.85 -                //e.g. specialization takes double and callsite says "object". reject.
    1.86 -                //but if specialization says double and callsite says "int" or "long" or "double", that's fine
    1.87 -                return false;
    1.88 -            }
    1.89 -        }
    1.90 -
    1.91 -        return true; // anything goes for return type, take the convenient one and it will be upcasted thru dynalink magic.
    1.92 -    }
    1.93 -
    1.94 -    private static int weigh(final MethodType t) {
    1.95 -        int weight = Type.typeFor(t.returnType()).getWeight();
    1.96 -        for (final Class<?> paramType : t.parameterArray()) {
    1.97 -            final int pweight = Type.typeFor(paramType).getWeight();
    1.98 -            weight += pweight;
    1.99 -        }
   1.100 -        return weight;
   1.101 -    }
   1.102 -}

mercurial