src/share/classes/sun/tools/tree/SynchronizedStatement.java

Print this page


   1 /*
   2  * Copyright (c) 1994, 2003, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


 103         }
 104         if (body != null) {
 105             cost += body.costInline(thresh, env,ctx);
 106         }
 107         return cost;
 108     }
 109 
 110     /**
 111      * Code
 112      */
 113     public void code(Environment env, Context ctx, Assembler asm) {
 114         ClassDefinition clazz = ctx.field.getClassDefinition();
 115         expr.codeValue(env, ctx, asm);
 116         ctx = new Context(ctx);
 117 
 118         if (needReturnSlot) {
 119             Type returnType = ctx.field.getType().getReturnType();
 120             LocalMember localfield = new LocalMember(0, clazz, 0, returnType,
 121                                                    idFinallyReturnValue);
 122             ctx.declare(env, localfield);
 123             env.debugOutput("Assigning return slot to " + localfield.number);
 124         }
 125 
 126         LocalMember f1 = new LocalMember(where, clazz, 0, Type.tObject, null);
 127         LocalMember f2 = new LocalMember(where, clazz, 0, Type.tInt, null);
 128         Integer num1 = new Integer(ctx.declare(env, f1));
 129         Integer num2 = new Integer(ctx.declare(env, f2));
 130 
 131         Label endLabel = new Label();
 132 
 133         TryData td = new TryData();
 134         td.add(null);
 135 
 136         // lock the object
 137         asm.add(where, opc_astore, num1);
 138         asm.add(where, opc_aload, num1);
 139         asm.add(where, opc_monitorenter);
 140 
 141         // Main body
 142         CodeContext bodyctx = new CodeContext(ctx, this);
 143         asm.add(where, opc_try, td);


   1 /*
   2  * Copyright (c) 1994, 2014, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


 103         }
 104         if (body != null) {
 105             cost += body.costInline(thresh, env,ctx);
 106         }
 107         return cost;
 108     }
 109 
 110     /**
 111      * Code
 112      */
 113     public void code(Environment env, Context ctx, Assembler asm) {
 114         ClassDefinition clazz = ctx.field.getClassDefinition();
 115         expr.codeValue(env, ctx, asm);
 116         ctx = new Context(ctx);
 117 
 118         if (needReturnSlot) {
 119             Type returnType = ctx.field.getType().getReturnType();
 120             LocalMember localfield = new LocalMember(0, clazz, 0, returnType,
 121                                                    idFinallyReturnValue);
 122             ctx.declare(env, localfield);
 123             Environment.debugOutput("Assigning return slot to " + localfield.number);
 124         }
 125 
 126         LocalMember f1 = new LocalMember(where, clazz, 0, Type.tObject, null);
 127         LocalMember f2 = new LocalMember(where, clazz, 0, Type.tInt, null);
 128         Integer num1 = new Integer(ctx.declare(env, f1));
 129         Integer num2 = new Integer(ctx.declare(env, f2));
 130 
 131         Label endLabel = new Label();
 132 
 133         TryData td = new TryData();
 134         td.add(null);
 135 
 136         // lock the object
 137         asm.add(where, opc_astore, num1);
 138         asm.add(where, opc_aload, num1);
 139         asm.add(where, opc_monitorenter);
 140 
 141         // Main body
 142         CodeContext bodyctx = new CodeContext(ctx, this);
 143         asm.add(where, opc_try, td);