src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/ArgumentSetter.java
author hannesw
Wed, 21 Mar 2018 16:55:34 +0100
changeset 49275 c639a6b33c5c
parent 47216 71c04702a3d5
permissions -rw-r--r--
8199869: Missing copyright headers in nashorn source code Reviewed-by: sundar
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
16206
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents:
diff changeset
     1
/*
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents:
diff changeset
     2
 * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents:
diff changeset
     4
 *
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents:
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents:
diff changeset
    10
 *
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents:
diff changeset
    15
 * accompanied this code).
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents:
diff changeset
    16
 *
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents:
diff changeset
    20
 *
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents:
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents:
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents:
diff changeset
    23
 * questions.
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents:
diff changeset
    24
 */
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents:
diff changeset
    25
package jdk.nashorn.internal.runtime;
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents:
diff changeset
    26
16228
df28320aa080 8007900: Function binding is inefficient
attila
parents: 16226
diff changeset
    27
import static jdk.nashorn.internal.codegen.CompilerConstants.staticCallNoLookup;
16206
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents:
diff changeset
    28
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents:
diff changeset
    29
import jdk.nashorn.internal.codegen.CompilerConstants.Call;
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents:
diff changeset
    30
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents:
diff changeset
    31
/**
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents:
diff changeset
    32
 * A class with static helper methods invoked from generated bytecode for setting values of parameters of variable-arity
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents:
diff changeset
    33
 * functions.
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents:
diff changeset
    34
 */
16226
0e4f37e6cc40 8007915: Nashorn IR, codegen, parser packages and Context instance should be inaccessible to user code
sundar
parents: 16206
diff changeset
    35
public final class ArgumentSetter {
0e4f37e6cc40 8007915: Nashorn IR, codegen, parser packages and Context instance should be inaccessible to user code
sundar
parents: 16206
diff changeset
    36
    private ArgumentSetter() {}
16206
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents:
diff changeset
    37
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents:
diff changeset
    38
    /** Method handle for setting a function argument at a given index in an arguments object. Used from generated bytecode */
16228
df28320aa080 8007900: Function binding is inefficient
attila
parents: 16226
diff changeset
    39
    public static final Call SET_ARGUMENT      = staticCallNoLookup(ArgumentSetter.class, "setArgument", void.class, Object.class, ScriptObject.class, int.class);
16206
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents:
diff changeset
    40
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents:
diff changeset
    41
    /** Method handle for setting a function argument at a given index in an arguments array. Used from generated bytecode */
16228
df28320aa080 8007900: Function binding is inefficient
attila
parents: 16226
diff changeset
    42
    public static final Call SET_ARRAY_ELEMENT = staticCallNoLookup(ArgumentSetter.class, "setArrayElement", void.class, Object.class, Object[].class, int.class);
16206
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents:
diff changeset
    43
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents:
diff changeset
    44
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents:
diff changeset
    45
    /**
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents:
diff changeset
    46
     * Used from generated bytecode to invoke {@link ScriptObject#setArgument(int, Object)} without having to reorder
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents:
diff changeset
    47
     * the arguments on the stack. When we're generating a store into the argument, we first have the value on the
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents:
diff changeset
    48
     * stack, and only afterwards load the target object and the index.
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents:
diff changeset
    49
     * @param value the value to write at the given argument index.
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents:
diff changeset
    50
     * @param arguments the arguments object that we're writing the value to
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents:
diff changeset
    51
     * @param key the index of the argument
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents:
diff changeset
    52
     */
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents:
diff changeset
    53
    public static void setArgument(final Object value, final ScriptObject arguments, final int key) {
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents:
diff changeset
    54
        arguments.setArgument(key, value);
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents:
diff changeset
    55
    }
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents:
diff changeset
    56
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents:
diff changeset
    57
    /**
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents:
diff changeset
    58
     * Used from generated bytecode to set a variable arity parameter - an array element - without having to reorder
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents:
diff changeset
    59
     * the arguments on the stack. When we're generating a store into the array, we first have the value on the
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents:
diff changeset
    60
     * stack, and only afterwards load the target array and the index.
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents:
diff changeset
    61
     * @param value the value to write at the given argument index.
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents:
diff changeset
    62
     * @param arguments the arguments array that we're writing the value to
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents:
diff changeset
    63
     * @param key the index of the argument
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents:
diff changeset
    64
     */
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents:
diff changeset
    65
    public static void setArrayElement(final Object value, final Object[] arguments, final int key) {
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents:
diff changeset
    66
        arguments[key] = value;
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents:
diff changeset
    67
    }
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents:
diff changeset
    68
}