Java Code Examples for jdk.nashorn.internal.codegen.types.Type#isObject()
The following examples show how to use
jdk.nashorn.internal.codegen.types.Type#isObject() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FunctionNode.java From TencentKona-8 with GNU General Public License v2.0 | 6 votes |
/** * Set the function return type * @param lc lexical context * @param returnType new return type * @return function node or a new one if state was changed */ public FunctionNode setReturnType(final LexicalContext lc, final Type returnType) { //we never bother with object types narrower than objects, that will lead to byte code verification errors //as for instance even if we know we are returning a string from a method, the code generator will always //treat it as an object, at least for now final Type type = returnType.isObject() ? Type.OBJECT : returnType; if (this.returnType == type) { return this; } return Node.replaceInLexicalContext( lc, this, new FunctionNode( this, lastToken, endParserState, flags, name, type, compileUnit, body, parameters, thisProperties, rootClass, source, namespace )); }
Example 2
Source File: SharedScopeCall.java From openjdk-8-source with GNU General Public License v2.0 | 6 votes |
private String getStaticSignature() { if (staticSignature == null) { if (paramTypes == null) { staticSignature = Type.getMethodDescriptor(returnType, Type.typeFor(ScriptObject.class), Type.INT); } else { final Type[] params = new Type[paramTypes.length + 2]; params[0] = Type.typeFor(ScriptObject.class); params[1] = Type.INT; int i = 2; for (Type type : paramTypes) { if (type.isObject()) { type = Type.OBJECT; } params[i++] = type; } staticSignature = Type.getMethodDescriptor(returnType, params); } } return staticSignature; }
Example 3
Source File: LiteralNode.java From hottub with GNU General Public License v2.0 | 6 votes |
private static Type computeElementType(final Expression[] value) { Type widestElementType = Type.INT; for (final Expression elem : value) { if (elem == null) { widestElementType = widestElementType.widest(Type.OBJECT); //no way to represent undefined as number break; } final Type type = elem.getType().isUnknown() ? Type.OBJECT : elem.getType(); if (type.isBoolean()) { //TODO fix this with explicit boolean types widestElementType = widestElementType.widest(Type.OBJECT); break; } widestElementType = widestElementType.widest(type); if (widestElementType.isObject()) { break; } } return widestElementType; }
Example 4
Source File: MethodEmitter.java From jdk8u60 with GNU General Public License v2.0 | 6 votes |
/** * Generate dynamic getter. Pop scope from stack. Push result * * @param valueType type of the value to set * @param name name of property * @param flags call site flags * @param isMethod should it prefer retrieving methods * @param isIndex is this an index operation? * @return the method emitter */ MethodEmitter dynamicGet(final Type valueType, final String name, final int flags, final boolean isMethod, final boolean isIndex) { if (name.length() > LARGE_STRING_THRESHOLD) { // use getIndex for extremely long names return load(name).dynamicGetIndex(valueType, flags, isMethod); } debug("dynamic_get", name, valueType, getProgramPoint(flags)); Type type = valueType; if (type.isObject() || type.isBoolean()) { type = Type.OBJECT; //promote e.g strings to object generic setter } popType(Type.SCOPE); method.visitInvokeDynamicInsn(dynGetOperation(isMethod, isIndex) + ':' + NameCodec.encode(name), Type.getMethodDescriptor(type, Type.OBJECT), LINKERBOOTSTRAP, flags); pushType(type); convert(valueType); //most probably a nop return this; }
Example 5
Source File: FunctionNode.java From jdk8u_nashorn with GNU General Public License v2.0 | 6 votes |
/** * Set the function return type * @param lc lexical context * @param returnType new return type * @return function node or a new one if state was changed */ public FunctionNode setReturnType(final LexicalContext lc, final Type returnType) { //we never bother with object types narrower than objects, that will lead to byte code verification errors //as for instance even if we know we are returning a string from a method, the code generator will always //treat it as an object, at least for now final Type type = returnType.isObject() ? Type.OBJECT : returnType; if (this.returnType == type) { return this; } return Node.replaceInLexicalContext( lc, this, new FunctionNode( this, lastToken, endParserState, flags, name, type, compileUnit, body, parameters, thisProperties, rootClass, source, namespace )); }
Example 6
Source File: LiteralNode.java From jdk8u60 with GNU General Public License v2.0 | 6 votes |
private static Type computeElementType(final Expression[] value) { Type widestElementType = Type.INT; for (final Expression elem : value) { if (elem == null) { widestElementType = widestElementType.widest(Type.OBJECT); //no way to represent undefined as number break; } final Type type = elem.getType().isUnknown() ? Type.OBJECT : elem.getType(); if (type.isBoolean()) { //TODO fix this with explicit boolean types widestElementType = widestElementType.widest(Type.OBJECT); break; } widestElementType = widestElementType.widest(type); if (widestElementType.isObject()) { break; } } return widestElementType; }
Example 7
Source File: LocalVariableConversion.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
private static char getTypeChar(final Type type) { if(type == Type.UNDEFINED) { return 'U'; } else if(type.isObject()) { return 'O'; } else if(type == Type.BOOLEAN) { return 'Z'; } return type.getBytecodeStackType(); }
Example 8
Source File: MethodEmitter.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
/** * Pop element from stack, convert to given type * * @param to type to convert to * * @return the method emitter */ MethodEmitter convert(final Type to) { final Type from = peekType(); final Type type = from.convert(method, to); if (type != null) { if (!from.isEquivalentTo(to)) { debug("convert", from, "->", to); } if (type != from) { final int l0 = stack.getTopLocalLoad(); popType(); pushType(type); // NOTE: conversions from a primitive type are considered to preserve the "load" property of the value // on the stack. Otherwise we could introduce temporary locals in a deoptimized rest-of (e.g. doing an // "i < x.length" where "i" is int and ".length" gets deoptimized to long would end up converting i to // long with "ILOAD i; I2L; LSTORE tmp; LLOAD tmp;"). Such additional temporary would cause an error // when restoring the state of the function for rest-of execution, as the not-yet deoptimized variant // would have the (now invalidated) assumption that "x.length" is an int, so it wouldn't have the I2L, // and therefore neither the subsequent LSTORE tmp; LLOAD tmp;. By making sure conversions from a // primitive type don't erase the "load" information, we don't introduce temporaries in the deoptimized // rest-of that didn't exist in the more optimistic version that triggered the deoptimization. // NOTE: as a more general observation, we could theoretically track the operations required to // reproduce any stack value as long as they are all local loads, constant loads, and stack operations. // We won't go there in the current system if(!from.isObject()) { stack.markLocalLoad(l0); } } } return this; }
Example 9
Source File: LocalVariableConversion.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
private static char getTypeChar(final Type type) { if(type == Type.UNDEFINED) { return 'U'; } else if(type.isObject()) { return 'O'; } else if(type == Type.BOOLEAN) { return 'Z'; } return type.getBytecodeStackType(); }
Example 10
Source File: LocalVariableConversion.java From hottub with GNU General Public License v2.0 | 5 votes |
private static char getTypeChar(final Type type) { if(type == Type.UNDEFINED) { return 'U'; } else if(type.isObject()) { return 'O'; } else if(type == Type.BOOLEAN) { return 'Z'; } return type.getBytecodeStackType(); }
Example 11
Source File: MethodEmitter.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
/** * Pop element from stack, convert to given type * * @param to type to convert to * * @return the method emitter */ MethodEmitter convert(final Type to) { final Type from = peekType(); final Type type = from.convert(method, to); if (type != null) { if (!from.isEquivalentTo(to)) { debug("convert", from, "->", to); } if (type != from) { final int l0 = stack.getTopLocalLoad(); popType(); pushType(type); // NOTE: conversions from a primitive type are considered to preserve the "load" property of the value // on the stack. Otherwise we could introduce temporary locals in a deoptimized rest-of (e.g. doing an // "i < x.length" where "i" is int and ".length" gets deoptimized to long would end up converting i to // long with "ILOAD i; I2L; LSTORE tmp; LLOAD tmp;"). Such additional temporary would cause an error // when restoring the state of the function for rest-of execution, as the not-yet deoptimized variant // would have the (now invalidated) assumption that "x.length" is an int, so it wouldn't have the I2L, // and therefore neither the subsequent LSTORE tmp; LLOAD tmp;. By making sure conversions from a // primitive type don't erase the "load" information, we don't introduce temporaries in the deoptimized // rest-of that didn't exist in the more optimistic version that triggered the deoptimization. // NOTE: as a more general observation, we could theoretically track the operations required to // reproduce any stack value as long as they are all local loads, constant loads, and stack operations. // We won't go there in the current system if(!from.isObject()) { stack.markLocalLoad(l0); } } } return this; }
Example 12
Source File: MethodEmitter.java From nashorn with GNU General Public License v2.0 | 5 votes |
/** * Generate dynamic setter. Pop receiver and property from stack. * * @param valueType the type of the value to set * @param name name of property * @param flags call site flags */ void dynamicSet(final Type valueType, final String name, final int flags) { debug("dynamic_set", name, peekType()); Type type = valueType; if (type.isObject() || type.isBoolean()) { //promote strings to objects etc type = Type.OBJECT; convert(Type.OBJECT); //TODO bad- until we specialize boolean setters, } popType(type); popType(Type.SCOPE); method.visitInvokeDynamicInsn("dyn:setProp|setElem:" + NameCodec.encode(name), methodDescriptor(void.class, Object.class, type.getTypeClass()), LINKERBOOTSTRAP, flags); }
Example 13
Source File: MethodEmitter.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 5 votes |
/** * Pop element from stack, convert to given type * * @param to type to convert to * * @return the method emitter */ MethodEmitter convert(final Type to) { final Type from = peekType(); final Type type = from.convert(method, to); if (type != null) { if (!from.isEquivalentTo(to)) { debug("convert", from, "->", to); } if (type != from) { final int l0 = stack.getTopLocalLoad(); popType(); pushType(type); // NOTE: conversions from a primitive type are considered to preserve the "load" property of the value // on the stack. Otherwise we could introduce temporary locals in a deoptimized rest-of (e.g. doing an // "i < x.length" where "i" is int and ".length" gets deoptimized to long would end up converting i to // long with "ILOAD i; I2L; LSTORE tmp; LLOAD tmp;"). Such additional temporary would cause an error // when restoring the state of the function for rest-of execution, as the not-yet deoptimized variant // would have the (now invalidated) assumption that "x.length" is an int, so it wouldn't have the I2L, // and therefore neither the subsequent LSTORE tmp; LLOAD tmp;. By making sure conversions from a // primitive type don't erase the "load" information, we don't introduce temporaries in the deoptimized // rest-of that didn't exist in the more optimistic version that triggered the deoptimization. // NOTE: as a more general observation, we could theoretically track the operations required to // reproduce any stack value as long as they are all local loads, constant loads, and stack operations. // We won't go there in the current system if(!from.isObject()) { stack.markLocalLoad(l0); } } } return this; }
Example 14
Source File: MethodEmitter.java From nashorn with GNU General Public License v2.0 | 4 votes |
private void debug(final int padConstant, final Object... args) { if (DEBUG) { final StringBuilder sb = new StringBuilder(); int pad; sb.append('#'); sb.append(++linePrefix); pad = 5 - sb.length(); while (pad > 0) { sb.append(' '); pad--; } if (stack != null && !stack.isEmpty()) { sb.append("{"); sb.append(stack.size()); sb.append(":"); for (int pos = 0; pos < stack.size(); pos++) { final Type t = stack.peek(pos); if (t == Type.SCOPE) { sb.append("scope"); } else if (t == Type.THIS) { sb.append("this"); } else if (t.isObject()) { String desc = t.getDescriptor(); int i; for (i = 0; desc.charAt(i) == '[' && i < desc.length(); i++) { sb.append('['); } desc = desc.substring(i); final int slash = desc.lastIndexOf('/'); if (slash != -1) { desc = desc.substring(slash + 1, desc.length() - 1); } if ("Object".equals(desc)) { sb.append('O'); } else { sb.append(desc); } } else { sb.append(t.getDescriptor()); } if (pos + 1 < stack.size()) { sb.append(' '); } } sb.append('}'); sb.append(' '); } pad = padConstant - sb.length(); while (pad > 0) { sb.append(' '); pad--; } for (final Object arg : args) { sb.append(arg); sb.append(' '); } if (env != null) { //early bootstrap code doesn't have inited context yet LOG.info(sb); if (DEBUG_TRACE_LINE == linePrefix) { new Throwable().printStackTrace(LOG.getOutputStream()); } } } }
Example 15
Source File: MethodEmitter.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 4 votes |
private void debug(final int padConstant, final Object... args) { if (debug) { final StringBuilder sb = new StringBuilder(); int pad; sb.append('#'); sb.append(++linePrefix); pad = 5 - sb.length(); while (pad > 0) { sb.append(' '); pad--; } if (isReachable() && !stack.isEmpty()) { sb.append("{"); sb.append(stack.size()); sb.append(":"); for (int pos = 0; pos < stack.size(); pos++) { final Type t = stack.peek(pos); if (t == Type.SCOPE) { sb.append("scope"); } else if (t == Type.THIS) { sb.append("this"); } else if (t.isObject()) { String desc = t.getDescriptor(); int i; for (i = 0; desc.charAt(i) == '[' && i < desc.length(); i++) { sb.append('['); } desc = desc.substring(i); final int slash = desc.lastIndexOf('/'); if (slash != -1) { desc = desc.substring(slash + 1, desc.length() - 1); } if ("Object".equals(desc)) { sb.append('O'); } else { sb.append(desc); } } else { sb.append(t.getDescriptor()); } final int loadIndex = stack.localLoads[stack.sp - 1 - pos]; if(loadIndex != Label.Stack.NON_LOAD) { sb.append('(').append(loadIndex).append(')'); } if (pos + 1 < stack.size()) { sb.append(' '); } } sb.append('}'); sb.append(' '); } pad = padConstant - sb.length(); while (pad > 0) { sb.append(' '); pad--; } for (final Object arg : args) { sb.append(arg); sb.append(' '); } if (context.getEnv() != null) { //early bootstrap code doesn't have inited context yet log.info(sb); if (DEBUG_TRACE_LINE == linePrefix) { new Throwable().printStackTrace(log.getOutputStream()); } } } }
Example 16
Source File: MethodEmitter.java From openjdk-8 with GNU General Public License v2.0 | 4 votes |
private void debug(final int padConstant, final Object... args) { if (DEBUG) { final StringBuilder sb = new StringBuilder(); int pad; sb.append('#'); sb.append(++linePrefix); pad = 5 - sb.length(); while (pad > 0) { sb.append(' '); pad--; } if (stack != null && !stack.isEmpty()) { sb.append("{"); sb.append(stack.size()); sb.append(":"); for (int pos = 0; pos < stack.size(); pos++) { final Type t = stack.peek(pos); if (t == Type.SCOPE) { sb.append("scope"); } else if (t == Type.THIS) { sb.append("this"); } else if (t.isObject()) { String desc = t.getDescriptor(); int i; for (i = 0; desc.charAt(i) == '[' && i < desc.length(); i++) { sb.append('['); } desc = desc.substring(i); final int slash = desc.lastIndexOf('/'); if (slash != -1) { desc = desc.substring(slash + 1, desc.length() - 1); } if ("Object".equals(desc)) { sb.append('O'); } else { sb.append(desc); } } else { sb.append(t.getDescriptor()); } if (pos + 1 < stack.size()) { sb.append(' '); } } sb.append('}'); sb.append(' '); } pad = padConstant - sb.length(); while (pad > 0) { sb.append(' '); pad--; } for (final Object arg : args) { sb.append(arg); sb.append(' '); } if (env != null) { //early bootstrap code doesn't have inited context yet LOG.info(sb); if (DEBUG_TRACE_LINE == linePrefix) { new Throwable().printStackTrace(LOG.getOutputStream()); } } } }
Example 17
Source File: MethodEmitter.java From jdk8u_nashorn with GNU General Public License v2.0 | 4 votes |
private void debug(final int padConstant, final Object... args) { if (debug) { final StringBuilder sb = new StringBuilder(); int pad; sb.append('#'); sb.append(++linePrefix); pad = 5 - sb.length(); while (pad > 0) { sb.append(' '); pad--; } if (isReachable() && !stack.isEmpty()) { sb.append("{"); sb.append(stack.size()); sb.append(":"); for (int pos = 0; pos < stack.size(); pos++) { final Type t = stack.peek(pos); if (t == Type.SCOPE) { sb.append("scope"); } else if (t == Type.THIS) { sb.append("this"); } else if (t.isObject()) { String desc = t.getDescriptor(); int i; for (i = 0; desc.charAt(i) == '[' && i < desc.length(); i++) { sb.append('['); } desc = desc.substring(i); final int slash = desc.lastIndexOf('/'); if (slash != -1) { desc = desc.substring(slash + 1, desc.length() - 1); } if ("Object".equals(desc)) { sb.append('O'); } else { sb.append(desc); } } else { sb.append(t.getDescriptor()); } final int loadIndex = stack.localLoads[stack.sp - 1 - pos]; if(loadIndex != Label.Stack.NON_LOAD) { sb.append('(').append(loadIndex).append(')'); } if (pos + 1 < stack.size()) { sb.append(' '); } } sb.append('}'); sb.append(' '); } pad = padConstant - sb.length(); while (pad > 0) { sb.append(' '); pad--; } for (final Object arg : args) { sb.append(arg); sb.append(' '); } if (context.getEnv() != null) { //early bootstrap code doesn't have inited context yet log.info(sb); if (DEBUG_TRACE_LINE == linePrefix) { new Throwable().printStackTrace(log.getOutputStream()); } } } }
Example 18
Source File: MethodEmitter.java From openjdk-jdk8u with GNU General Public License v2.0 | 4 votes |
private void debug(final int padConstant, final Object... args) { if (debug) { final StringBuilder sb = new StringBuilder(); int pad; sb.append('#'); sb.append(++linePrefix); pad = 5 - sb.length(); while (pad > 0) { sb.append(' '); pad--; } if (isReachable() && !stack.isEmpty()) { sb.append("{"); sb.append(stack.size()); sb.append(":"); for (int pos = 0; pos < stack.size(); pos++) { final Type t = stack.peek(pos); if (t == Type.SCOPE) { sb.append("scope"); } else if (t == Type.THIS) { sb.append("this"); } else if (t.isObject()) { String desc = t.getDescriptor(); int i; for (i = 0; desc.charAt(i) == '[' && i < desc.length(); i++) { sb.append('['); } desc = desc.substring(i); final int slash = desc.lastIndexOf('/'); if (slash != -1) { desc = desc.substring(slash + 1, desc.length() - 1); } if ("Object".equals(desc)) { sb.append('O'); } else { sb.append(desc); } } else { sb.append(t.getDescriptor()); } final int loadIndex = stack.localLoads[stack.sp - 1 - pos]; if(loadIndex != Label.Stack.NON_LOAD) { sb.append('(').append(loadIndex).append(')'); } if (pos + 1 < stack.size()) { sb.append(' '); } } sb.append('}'); sb.append(' '); } pad = padConstant - sb.length(); while (pad > 0) { sb.append(' '); pad--; } for (final Object arg : args) { sb.append(arg); sb.append(' '); } if (context.getEnv() != null) { //early bootstrap code doesn't have inited context yet log.info(sb); if (DEBUG_TRACE_LINE == linePrefix) { new Throwable().printStackTrace(log.getOutputStream()); } } } }
Example 19
Source File: RuntimeCallSite.java From openjdk-8 with GNU General Public License v2.0 | 4 votes |
private static char descFor(final Type type) { if (type.isObject()) { return 'O'; } return type.getDescriptor().charAt(0); }
Example 20
Source File: MethodEmitter.java From openjdk-jdk9 with GNU General Public License v2.0 | 4 votes |
private void debug(final int padConstant, final Object... args) { if (debug) { final StringBuilder sb = new StringBuilder(); int pad; sb.append('#'); sb.append(++linePrefix); pad = 5 - sb.length(); while (pad > 0) { sb.append(' '); pad--; } if (isReachable() && !stack.isEmpty()) { sb.append("{"); sb.append(stack.size()); sb.append(":"); for (int pos = 0; pos < stack.size(); pos++) { final Type t = stack.peek(pos); if (t == Type.SCOPE) { sb.append("scope"); } else if (t == Type.THIS) { sb.append("this"); } else if (t.isObject()) { String desc = t.getDescriptor(); int i; for (i = 0; desc.charAt(i) == '[' && i < desc.length(); i++) { sb.append('['); } desc = desc.substring(i); final int slash = desc.lastIndexOf('/'); if (slash != -1) { desc = desc.substring(slash + 1, desc.length() - 1); } if ("Object".equals(desc)) { sb.append('O'); } else { sb.append(desc); } } else { sb.append(t.getDescriptor()); } final int loadIndex = stack.localLoads[stack.sp - 1 - pos]; if(loadIndex != Label.Stack.NON_LOAD) { sb.append('(').append(loadIndex).append(')'); } if (pos + 1 < stack.size()) { sb.append(' '); } } sb.append('}'); sb.append(' '); } pad = padConstant - sb.length(); while (pad > 0) { sb.append(' '); pad--; } for (final Object arg : args) { sb.append(arg); sb.append(' '); } if (context.getEnv() != null) { //early bootstrap code doesn't have inited context yet log.info(sb); if (DEBUG_TRACE_LINE == linePrefix) { new Throwable().printStackTrace(log.getOutputStream()); } } } }