Source Code Cross Referenced for Label.java in  » Scripting » beanshell » bsh » org » objectweb » asm » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Scripting » beanshell » bsh.org.objectweb.asm 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /***
002:         * ASM: a very small and fast Java bytecode manipulation framework
003:         * Copyright (C) 2000 INRIA, France Telecom
004:         * Copyright (C) 2002 France Telecom
005:         *
006:         * This library is free software; you can redistribute it and/or
007:         * modify it under the terms of the GNU Lesser General Public
008:         * License as published by the Free Software Foundation; either
009:         * version 2 of the License, or (at your option) any later version.
010:         *
011:         * This library is distributed in the hope that it will be useful,
012:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
013:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
014:         * Lesser General Public License for more details.
015:         *
016:         * You should have received a copy of the GNU Lesser General Public
017:         * License along with this library; if not, write to the Free Software
018:         * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
019:         *
020:         * Contact: Eric.Bruneton@rd.francetelecom.com
021:         *
022:         * Author: Eric Bruneton
023:         */package bsh.org.objectweb.asm;
024:
025:        /**
026:         * A label represents a position in the bytecode of a method. Labels are used
027:         * for jump, goto, and switch instructions, and for try catch blocks.
028:         */
029:
030:        public class Label {
031:
032:            /**
033:             * The code writer to which this label belongs, or <tt>null</tt> if unknown.
034:             */
035:
036:            CodeWriter owner;
037:
038:            /**
039:             * Indicates if the position of this label is known.
040:             */
041:
042:            boolean resolved;
043:
044:            /**
045:             * The position of this label in the code, if known.
046:             */
047:
048:            int position;
049:
050:            /**
051:             * Number of forward references to this label, times two.
052:             */
053:
054:            private int referenceCount;
055:
056:            /**
057:             * Informations about forward references. Each forward reference is described
058:             * by two consecutive integers in this array: the first one is the position
059:             * of the first byte of the bytecode instruction that contains the forward
060:             * reference, while the second is the position of the first byte of the
061:             * forward reference itself. In fact the sign of the first integer indicates
062:             * if this reference uses 2 or 4 bytes, and its absolute value gives the
063:             * position of the bytecode instruction.
064:             */
065:
066:            private int[] srcAndRefPositions;
067:
068:            // --------------------------------------------------------------------------
069:            // Fields for the control flow graph analysis algorithm (used to compute the
070:            // maximum stack size). A control flow graph contains one node per "basic
071:            // block", and one edge per "jump" from one basic block to another. Each node
072:            // (i.e., each basic block) is represented by the Label object that
073:            // corresponds to the first instruction of this basic block. Each node also
074:            // stores the list of it successors in the graph, as a linked list of Edge
075:            // objects.
076:            // --------------------------------------------------------------------------
077:
078:            /**
079:             * The stack size at the beginning of this basic block.
080:             * This size is initially unknown. It is computed by the control flow
081:             * analysis algorithm (see {@link CodeWriter#visitMaxs visitMaxs}).
082:             */
083:
084:            int beginStackSize;
085:
086:            /**
087:             * The (relative) maximum stack size corresponding to this basic block. This
088:             * size is relative to the stack size at the beginning of the basic block,
089:             * i.e., the true maximum stack size is equal to {@link #beginStackSize
090:             * beginStackSize} + {@link #maxStackSize maxStackSize}.
091:             */
092:
093:            int maxStackSize;
094:
095:            /**
096:             * The successors of this node in the control flow graph. These successors
097:             * are stored in a linked list of {@link Edge Edge} objects, linked to each
098:             * other by their {@link Edge#next} field.
099:             */
100:
101:            Edge successors;
102:
103:            /**
104:             * The next basic block in the basic block stack.
105:             * See {@link CodeWriter#visitMaxs visitMaxs}.
106:             */
107:
108:            Label next;
109:
110:            /**
111:             * <tt>true</tt> if this basic block has been pushed in the basic block stack.
112:             * See {@link CodeWriter#visitMaxs visitMaxs}.
113:             */
114:
115:            boolean pushed;
116:
117:            // --------------------------------------------------------------------------
118:            // Constructor
119:            // --------------------------------------------------------------------------
120:
121:            /**
122:             * Constructs a new label.
123:             */
124:
125:            public Label() {
126:            }
127:
128:            // --------------------------------------------------------------------------
129:            // Methods to compute offsets and to manage forward references
130:            // --------------------------------------------------------------------------
131:
132:            /**
133:             * Puts a reference to this label in the bytecode of a method. If the position
134:             * of the label is known, the offset is computed and written directly.
135:             * Otherwise, a null offset is written and a new forward reference is declared
136:             * for this label.
137:             *
138:             * @param owner the code writer that calls this method.
139:             * @param out the bytecode of the method.
140:             * @param source the position of first byte of the bytecode instruction that
141:             *      contains this label.
142:             * @param wideOffset <tt>true</tt> if the reference must be stored in 4 bytes,
143:             *      or <tt>false</tt> if it must be stored with 2 bytes.
144:             * @throws IllegalArgumentException if this label has not been created by the
145:             *      given code writer.
146:             */
147:
148:            void put(final CodeWriter owner, final ByteVector out,
149:                    final int source, final boolean wideOffset) {
150:                if (CodeWriter.CHECK) {
151:                    if (this .owner == null) {
152:                        this .owner = owner;
153:                    } else if (this .owner != owner) {
154:                        throw new IllegalArgumentException();
155:                    }
156:                }
157:                if (resolved) {
158:                    if (wideOffset) {
159:                        out.put4(position - source);
160:                    } else {
161:                        out.put2(position - source);
162:                    }
163:                } else {
164:                    if (wideOffset) {
165:                        addReference(-1 - source, out.length);
166:                        out.put4(-1);
167:                    } else {
168:                        addReference(source, out.length);
169:                        out.put2(-1);
170:                    }
171:                }
172:            }
173:
174:            /**
175:             * Adds a forward reference to this label. This method must be called only for
176:             * a true forward reference, i.e. only if this label is not resolved yet. For
177:             * backward references, the offset of the reference can be, and must be,
178:             * computed and stored directly.
179:             *
180:             * @param sourcePosition the position of the referencing instruction. This
181:             *      position will be used to compute the offset of this forward reference.
182:             * @param referencePosition the position where the offset for this forward
183:             *      reference must be stored.
184:             */
185:
186:            private void addReference(final int sourcePosition,
187:                    final int referencePosition) {
188:                if (srcAndRefPositions == null) {
189:                    srcAndRefPositions = new int[6];
190:                }
191:                if (referenceCount >= srcAndRefPositions.length) {
192:                    int[] a = new int[srcAndRefPositions.length + 6];
193:                    System.arraycopy(srcAndRefPositions, 0, a, 0,
194:                            srcAndRefPositions.length);
195:                    srcAndRefPositions = a;
196:                }
197:                srcAndRefPositions[referenceCount++] = sourcePosition;
198:                srcAndRefPositions[referenceCount++] = referencePosition;
199:            }
200:
201:            /**
202:             * Resolves all forward references to this label. This method must be called
203:             * when this label is added to the bytecode of the method, i.e. when its
204:             * position becomes known. This method fills in the blanks that where left in
205:             * the bytecode by each forward reference previously added to this label.
206:             *
207:             * @param owner the code writer that calls this method.
208:             * @param position the position of this label in the bytecode.
209:             * @param data the bytecode of the method.
210:             * @return <tt>true</tt> if a blank that was left for this label was to small
211:             *      to store the offset. In such a case the corresponding jump instruction
212:             *      is replaced with a pseudo instruction (using unused opcodes) using an
213:             *      unsigned two bytes offset. These pseudo instructions will need to be
214:             *      replaced with true instructions with wider offsets (4 bytes instead of
215:             *      2). This is done in {@link CodeWriter#resizeInstructions}.
216:             * @throws IllegalArgumentException if this label has already been resolved,
217:             *      or if it has not been created by the given code writer.
218:             */
219:
220:            boolean resolve(final CodeWriter owner, final int position,
221:                    final byte[] data) {
222:                if (CodeWriter.CHECK) {
223:                    if (this .owner == null) {
224:                        this .owner = owner;
225:                    }
226:                    if (resolved || this .owner != owner) {
227:                        throw new IllegalArgumentException();
228:                    }
229:                }
230:                boolean needUpdate = false;
231:                this .resolved = true;
232:                this .position = position;
233:                int i = 0;
234:                while (i < referenceCount) {
235:                    int source = srcAndRefPositions[i++];
236:                    int reference = srcAndRefPositions[i++];
237:                    int offset;
238:                    if (source >= 0) {
239:                        offset = position - source;
240:                        if (offset < Short.MIN_VALUE
241:                                || offset > Short.MAX_VALUE) {
242:                            // changes the opcode of the jump instruction, in order to be able to
243:                            // find it later (see resizeInstructions in CodeWriter). These
244:                            // temporary opcodes are similar to jump instruction opcodes, except
245:                            // that the 2 bytes offset is unsigned (and can therefore represent
246:                            // values from 0 to 65535, which is sufficient since the size of a
247:                            // method is limited to 65535 bytes).
248:                            int opcode = data[reference - 1] & 0xFF;
249:                            if (opcode <= Constants.JSR) {
250:                                // changes IFEQ ... JSR to opcodes 202 to 217 (inclusive)
251:                                data[reference - 1] = (byte) (opcode + 49);
252:                            } else {
253:                                // changes IFNULL and IFNONNULL to opcodes 218 and 219 (inclusive)
254:                                data[reference - 1] = (byte) (opcode + 20);
255:                            }
256:                            needUpdate = true;
257:                        }
258:                        data[reference++] = (byte) (offset >>> 8);
259:                        data[reference] = (byte) offset;
260:                    } else {
261:                        offset = position + source + 1;
262:                        data[reference++] = (byte) (offset >>> 24);
263:                        data[reference++] = (byte) (offset >>> 16);
264:                        data[reference++] = (byte) (offset >>> 8);
265:                        data[reference] = (byte) offset;
266:                    }
267:                }
268:                return needUpdate;
269:            }
270:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.