List of usage examples for org.eclipse.jdt.internal.compiler.codegen Opcodes OPC_invokespecial
byte OPC_invokespecial
To view the source code for org.eclipse.jdt.internal.compiler.codegen Opcodes OPC_invokespecial.
Click Source Link
From source file:org.eclipse.objectteams.otdt.internal.core.compiler.lifting.Lifting.java
License:Open Source License
/** * API for AbstractMethodDeclaration://from w ww .j a v a 2 s . c om * * Create a byte code sequence for a runtime check in a creation method: * R _OT$create_OT$R(B b) { * if (this._OT$cache_OT$R.contains(b)) * throw new DuplicateRoleException("R"); * // continue regular code. * } * * Note, the need for this runtime check is detected quite late. * At this point it is easier to create the byte code sequence directly, * rather the creating AST first. */ public static void createDuplicateRoleCheck(CodeStream codeStream, AbstractMethodDeclaration method) { MethodBinding binding = method.binding; Scope scope = method.scope; ReferenceBinding roleType = (ReferenceBinding) binding.returnType; String roleName = new String(roleType.readableName()); // TODO(SH): check why roleType.getRoleModel().getClassPartBinding().roleModel may yield a different result. // I think it occured in haeder/stopwatch from smile-CVS. //RoleModel role = roleType.getRealClass().roleModel; char[] cacheName = LiftingEnvironment.getCacheName(roleType.roleModel.getBoundRootRole()); ReferenceBinding teamBinding = roleType.enclosingType();//role.getTeamModel().getBinding(); FieldBinding cache = TypeAnalyzer.findField(teamBinding, cacheName, /*static*/false, /*outer*/false, ITranslationStates.STATE_FULL_LIFTING); // generated by this state if (cache == null) throw new InternalCompilerError("generated cache field not found: " + new String(cacheName)); //$NON-NLS-1$ ReferenceBinding map = (ReferenceBinding) scope.getType(IOTConstants.WEAK_HASH_MAP, 3); MethodBinding contains = map.getMethod(scope, IOTConstants.CONTAINS_KEY); ReferenceBinding exc = (ReferenceBinding) scope.getType(IOTConstants.ORG_OBJECTTEAMS_DUPLICATE_ROLE, 3); TypeBinding[] types = new TypeBinding[] { scope.getJavaLangString() }; MethodBinding excInit = exc.getExactConstructor(types); BranchLabel normalCase = new BranchLabel(codeStream); codeStream.aload_0(); // this codeStream.fieldAccess(Opcodes.OPC_getfield, cache, teamBinding); // getfield MyTeam._OT$cache_OT$R Ljava/util/WeakHashMap; codeStream.aload_1(); // arg0 codeStream.invoke(Opcodes.OPC_invokevirtual, contains, map); // invokevirtual java.util.WeakHashMap.containsKey (Ljava/lang/Object;)Z codeStream.ifeq(normalCase); // false -> #endif codeStream.new_(exc); // new <org.objectteams.DuplicateRoleException> codeStream.dup(); // dup codeStream.ldc(roleName); // ldc "R" codeStream.invoke(Opcodes.OPC_invokespecial, excInit, exc); // invokespecial org.objectteams.DuplicateRoleException.<init> (Ljava/lang/String;)V codeStream.athrow(); // athrow normalCase.place(); // #endif }
From source file:org.eclipse.objectteams.otdt.internal.core.compiler.lookup.SyntheticBaseCallSurrogate.java
License:Open Source License
/** Directly generate the instruction for this method's body (no AST available). */ public void generateInstructions(CodeStream codeStream) { codeStream.new_(this.errorType); codeStream.dup();/*from w ww .j a v a2 s . c o m*/ codeStream.ldc("Binding error: base-call impossible!"); //$NON-NLS-1$ MethodBinding ctorBinding = ((ReferenceBinding) this.errorType) .getExactConstructor(new TypeBinding[] { this.stringType }); codeStream.invoke(Opcodes.OPC_invokespecial, ctorBinding, this.errorType); codeStream.athrow(); codeStream.aconst_null(); // always generalized to Object codeStream.areturn(); }
From source file:org.eclipse.objectteams.otdt.internal.core.compiler.lookup.SyntheticRoleBridgeMethodBinding.java
License:Open Source License
@Override public void generateInstructions(CodeStream codeStream) { TypeBinding[] arguments = this.parameters; int argLen = arguments.length; TypeBinding[] targetParameters = this.targetMethod.parameters; int resolvedPosition = 0; int argIdx = 0; int targetIdx = 0; switch (this.purpose) { case RoleMethodBridgeInner: codeStream.aload_0(); // synthetic first arg is the receiver role codeStream.checkcast(this.targetMethod.declaringClass); resolvedPosition = 1; // first arg is processed argIdx = 1;//from w w w.j a va 2 s . c o m if (this.targetMethod.isStatic()) { codeStream.iconst_0(); // dummy int codeStream.aload_2(); // pass synth. team arg argIdx += 2; resolvedPosition += 2; } break; case RoleMethodBridgeOuter: resolvedPosition = 1; // ignore team instance at 0 argIdx = 0; // pass all args unchanged break; } while (argIdx < argLen) { TypeBinding parameter = targetParameters[targetIdx++]; TypeBinding argument = arguments[argIdx++]; codeStream.load(argument, resolvedPosition); if (TypeBinding.notEquals(argument, parameter)) codeStream.checkcast(parameter); switch (parameter.id) { case TypeIds.T_long: case TypeIds.T_double: resolvedPosition += 2; break; default: resolvedPosition++; break; } } if (this.targetMethod.isStatic()) codeStream.invoke(Opcodes.OPC_invokestatic, this.targetMethod, null); else codeStream.invoke(Opcodes.OPC_invokespecial, this.targetMethod, null); // non-static private role method switch (this.targetMethod.returnType.id) { case TypeIds.T_void: codeStream.return_(); break; case TypeIds.T_boolean: case TypeIds.T_byte: case TypeIds.T_char: case TypeIds.T_short: case TypeIds.T_int: codeStream.ireturn(); break; case TypeIds.T_long: codeStream.lreturn(); break; case TypeIds.T_float: codeStream.freturn(); break; case TypeIds.T_double: codeStream.dreturn(); break; default: codeStream.areturn(); } }
From source file:org.eclipse.objectteams.otdt.internal.core.compiler.statemachine.transformer.RoleMigrationImplementor.java
License:Open Source License
private static void doAddMigrateMethod(TypeDeclaration roleClassDecl, char[] selector, TypeReference argumentTypeRef, TypeReference returnTypeRef, final String kind, final char[] cacheName) { AstGenerator gen = new AstGenerator(roleClassDecl.sourceStart, roleClassDecl.sourceEnd); MethodDeclaration migrate = new MethodDeclaration(roleClassDecl.compilationResult) { @Override//from w ww . j av a 2 s. c om protected void endOfMethodHook(ClassFile classfile) { // common code for both variants: CodeStream codeStream = classfile.codeStream; // if (otherTeam == null) BranchLabel goOn = new BranchLabel(codeStream); codeStream.aload_1(); //otherTeam / otherBase codeStream.ifnonnull(goOn); // { throw new NullPointerException("Team/base argument must not be null"); } ReferenceBinding npeBinding = (ReferenceBinding) this.scope.getType(JAVA_LANG_NULLPOINTEREXCEPTION, 3); codeStream.new_(npeBinding); codeStream.dup(); MethodBinding npeStringCtor = getStringArgCtor(npeBinding); if (npeStringCtor == null) throw new InternalCompilerError( "Expected constructor NullPointerException.<init>(String) not found"); //$NON-NLS-1$ codeStream.ldc(kind + " argument must not be null"); //$NON-NLS-1$ codeStream.invoke(Opcodes.OPC_invokespecial, npeStringCtor, npeBinding); codeStream.athrow(); goOn.place(); // specific code: if (kind == TEAM) genMigrateToTeamInstructions(codeStream, this.scope.enclosingSourceType()); else genMigrateToBaseInstructions(codeStream, this.scope.enclosingSourceType(), this.scope, cacheName); } private MethodBinding getStringArgCtor(ReferenceBinding npeBinding) { MethodBinding[] ctors = npeBinding.getMethods(TypeConstants.INIT); for (MethodBinding ctor : ctors) { if (ctor.parameters.length == 1 && ctor.parameters[0].id == TypeIds.T_JavaLangString) return ctor; } return null; } @Override public void analyseCode(ClassScope classScope, FlowContext flowContext, FlowInfo flowInfo) { // noop } }; gen.setMethodPositions(migrate); migrate.isGenerated = true; migrate.modifiers = AccPublic | AccSynchronized; migrate.typeParameters = new TypeParameter[] { gen.unboundedTypeParameter(RoleMigrationImplementor.TYPEPARAM) }; migrate.returnType = returnTypeRef; migrate.selector = selector; migrate.arguments = new Argument[] { gen.argument(("other" + kind).toCharArray(), argumentTypeRef) }; //$NON-NLS-1$ migrate.statements = new Statement[0]; migrate.hasParsedStatements = true; AstEdit.addMethod(roleClassDecl, migrate); }