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

Thu, 14 Feb 2013 13:01:52 +0100

author
lagergren
date
Thu, 14 Feb 2013 13:01:52 +0100
changeset 89
43e32b36153c
parent 80
8742be332c8a
child 96
e478708faa22
permissions
-rw-r--r--

8008199: Lazy compilation and trampoline implementation
Summary: The code pipeline now supports lazy compilation, which can be used to only compile certain FunctionNodes and leave others be, saving startup time. When these uncompiled nodes are hit, a trampoline will force them to be recompiled. This can also be used to specialize compilation fixing parameter types and return types to a callsite specific compilation. This will give performance.
Reviewed-by: attila, sundar

jlaskey@3 1 /*
jlaskey@7 2 * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
jlaskey@3 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
jlaskey@3 4 *
jlaskey@3 5 * This code is free software; you can redistribute it and/or modify it
jlaskey@3 6 * under the terms of the GNU General Public License version 2 only, as
jlaskey@3 7 * published by the Free Software Foundation. Oracle designates this
jlaskey@3 8 * particular file as subject to the "Classpath" exception as provided
jlaskey@3 9 * by Oracle in the LICENSE file that accompanied this code.
jlaskey@3 10 *
jlaskey@3 11 * This code is distributed in the hope that it will be useful, but WITHOUT
jlaskey@3 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
jlaskey@3 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
jlaskey@3 14 * version 2 for more details (a copy is included in the LICENSE file that
jlaskey@3 15 * accompanied this code).
jlaskey@3 16 *
jlaskey@3 17 * You should have received a copy of the GNU General Public License version
jlaskey@3 18 * 2 along with this work; if not, write to the Free Software Foundation,
jlaskey@3 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
jlaskey@3 20 *
jlaskey@3 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
jlaskey@3 22 * or visit www.oracle.com if you need additional information or have any
jlaskey@3 23 * questions.
jlaskey@3 24 */
jlaskey@3 25
jlaskey@3 26 package jdk.nashorn.internal.runtime;
jlaskey@3 27
jlaskey@3 28 import static jdk.nashorn.internal.runtime.linker.Lookup.MH;
jlaskey@3 29
jlaskey@3 30 import java.lang.invoke.MethodHandle;
jlaskey@3 31 import jdk.nashorn.internal.codegen.objects.ObjectClassGenerator;
jlaskey@3 32
jlaskey@3 33 /**
jlaskey@3 34 * This class represents the result from a find property search.
jlaskey@3 35 */
jlaskey@3 36 public final class FindProperty {
jlaskey@80 37 /** Object where search began. */
jlaskey@3 38 private final ScriptObject self;
lagergren@89 39
jlaskey@80 40 /** Object where search finish. */
jlaskey@3 41 private final ScriptObject prototype;
jlaskey@80 42
jlaskey@80 43 /** Found property. */
jlaskey@3 44 private final Property property;
jlaskey@3 45
jlaskey@3 46 /**
jlaskey@3 47 * Constructor
jlaskey@3 48 *
jlaskey@80 49 * @param self script object where search began
jlaskey@3 50 * @param prototype prototype where property was found, may be {@code self} if not inherited
jlaskey@3 51 * @param property property that was search result
jlaskey@3 52 */
jlaskey@80 53 public FindProperty(final ScriptObject self, final ScriptObject prototype, final Property property) {
jlaskey@3 54 this.self = self;
jlaskey@3 55 this.prototype = prototype;
jlaskey@3 56 this.property = property;
jlaskey@3 57 }
jlaskey@3 58
jlaskey@3 59 /**
jlaskey@3 60 * Ask for a getter that returns the given type. The type has nothing to do with the
jlaskey@3 61 * internal representation of the property. It may be an Object (boxing primitives) or
jlaskey@3 62 * a primitive (primitive fields with -Dnashorn.fields.dual=true)
jlaskey@3 63 * @see ObjectClassGenerator
jlaskey@3 64 *
jlaskey@3 65 * @param type type of getter, e.g. int.class if we want a function with {@code get()I} signature
jlaskey@3 66 * @return method handle for the getter
jlaskey@3 67 */
jlaskey@3 68 public MethodHandle getGetter(final Class<?> type) {
jlaskey@3 69 MethodHandle getter = property.getGetter(type);
jlaskey@3 70 if (property instanceof UserAccessorProperty) {
jlaskey@3 71 final UserAccessorProperty uc = (UserAccessorProperty)property;
jlaskey@3 72 getter = MH.insertArguments(getter, 0, isInherited() ? getOwner() : null, uc.getGetterSlot());
jlaskey@3 73 }
jlaskey@3 74 return getter;
jlaskey@3 75 }
jlaskey@3 76
jlaskey@3 77 /**
jlaskey@80 78 * Ask for a setter that sets the given type. The type has nothing to do with the
jlaskey@80 79 * internal representation of the property. It may be an Object (boxing primitives) or
jlaskey@80 80 * a primitive (primitive fields with -Dnashorn.fields.dual=true)
jlaskey@80 81 * @see ObjectClassGenerator
jlaskey@80 82 *
jlaskey@80 83 * @param type type of setter, e.g. int.class if we want a function with {@code set(I)V} signature
jlaskey@80 84 * @param strict are we in strict mode
jlaskey@80 85 *
jlaskey@80 86 * @return method handle for the getter
jlaskey@3 87 */
jlaskey@80 88 public MethodHandle getSetter(final Class<?> type, final boolean strict) {
jlaskey@80 89 MethodHandle setter = property.getSetter(type, getOwner().getMap());
jlaskey@80 90 if (property instanceof UserAccessorProperty) {
jlaskey@80 91 final UserAccessorProperty uc = (UserAccessorProperty) property;
jlaskey@80 92 setter = MH.insertArguments(setter, 0, (isInherited() ? getOwner() : null),
jlaskey@80 93 uc.getSetterSlot(), strict? property.getKey() : null);
jlaskey@80 94 }
jlaskey@80 95
jlaskey@80 96 return setter;
jlaskey@3 97 }
jlaskey@3 98
jlaskey@3 99 /**
jlaskey@80 100 * Return the {@code ScriptObject} owning of the property: this means the prototype.
jlaskey@80 101 * @return owner of property
jlaskey@3 102 */
jlaskey@80 103 public ScriptObject getOwner() {
jlaskey@80 104 return prototype;
jlaskey@3 105 }
jlaskey@3 106
jlaskey@3 107 /**
jlaskey@3 108 * Return the property that was found
jlaskey@3 109 * @return property
jlaskey@3 110 */
jlaskey@3 111 public Property getProperty() {
jlaskey@3 112 return property;
jlaskey@3 113 }
jlaskey@3 114
jlaskey@3 115 /**
jlaskey@3 116 * Check if the property found was inherited, i.e. not directly in the self
jlaskey@3 117 * @return true if inherited property
jlaskey@3 118 */
jlaskey@3 119 public boolean isInherited() {
jlaskey@3 120 return self != prototype;
jlaskey@3 121 }
jlaskey@3 122
jlaskey@3 123 /**
jlaskey@3 124 * Check if the property found was NOT inherited, i.e. defined in the script
jlaskey@3 125 * object, rather than in the prototype
jlaskey@3 126 * @return true if not inherited
jlaskey@3 127 */
jlaskey@3 128 public boolean isSelf() {
jlaskey@3 129 return self == prototype;
jlaskey@3 130 }
jlaskey@3 131
jlaskey@3 132 /**
jlaskey@3 133 * Check if the property is in the scope
jlaskey@3 134 * @return true if on scope
jlaskey@3 135 */
jlaskey@3 136 public boolean isScope() {
jlaskey@80 137 return prototype.isScope();
jlaskey@3 138 }
jlaskey@3 139
jlaskey@3 140 }
jlaskey@3 141

mercurial