< prev index next >

agent/src/share/classes/sun/jvm/hotspot/tools/jcore/ClassWriter.java

Print this page
rev 4134 : 7178145: Change constMethodOop::_exception_table to optionally inlined u2 table.
Summary: Change constMethodOop::_exception_table to optionally inlined u2 table.
Reviewed-by: bdelsart, coleenp, kamg
   1 /*
   2  * Copyright (c) 2002, 2011, 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.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *


 487             methodAttributeCount++;
 488 
 489         dos.writeShort(methodAttributeCount);
 490         if (DEBUG) debugMessage("\tmethod attribute count = " + methodAttributeCount);
 491 
 492         if (hasSyn) {
 493             if (DEBUG) debugMessage("\tmethod is synthetic");
 494             writeSynthetic();
 495         }
 496 
 497         if (isCodeAvailable) {
 498             byte[] code = m.getByteCode();
 499             short codeAttrCount = 0;
 500             int codeSize  = 2           /* max_stack   */ +
 501                             2           /* max_locals  */ +
 502                             4           /* code_length */ +
 503                             code.length /* code        */ +
 504                             2           /* exp. table len.  */ +
 505                             2           /* code attr. count */;
 506 
 507             TypeArray exceptionTable = m.getExceptionTable();
 508             final int exceptionTableLen = (int) exceptionTable.getLength();
 509             if (exceptionTableLen != 0) {



 510                 if (DEBUG) debugMessage("\tmethod has exception table");
 511                 codeSize += (exceptionTableLen / 4) /* exception table is 4-tuple array */
 512                                          * (2 /* start_pc     */ +
 513                                             2 /* end_pc       */ +
 514                                             2 /* handler_pc   */ +
 515                                             2 /* catch_type   */);
 516             }
 517 
 518             boolean hasLineNumberTable = m.hasLineNumberTable();
 519             LineNumberTableElement[] lineNumberTable = null;
 520             int lineNumberAttrLen = 0;
 521 
 522             if (hasLineNumberTable) {
 523                 if (DEBUG) debugMessage("\tmethod has line number table");
 524                 lineNumberTable = m.getLineNumberTable();
 525                 if (DEBUG) debugMessage("\t\tline table length = " + lineNumberTable.length);
 526 
 527                 lineNumberAttrLen = 2 /* line number table length         */ +
 528                            lineNumberTable.length * (2 /* start_pc */ + 2 /* line_number */);
 529 
 530                 codeSize += 2 /* line number table attr index     */ +
 531                             4 /* line number table attr length    */ +


 569 
 570             // start writing Code
 571 
 572             writeIndex(_codeIndex);
 573 
 574             dos.writeInt(codeSize);
 575             if (DEBUG) debugMessage("\tcode attribute length = " + codeSize);
 576 
 577             dos.writeShort((short) m.getMaxStack());
 578             if (DEBUG) debugMessage("\tmax stack = " + m.getMaxStack());
 579 
 580             dos.writeShort((short) m.getMaxLocals());
 581             if (DEBUG) debugMessage("\tmax locals = " + m.getMaxLocals());
 582 
 583             dos.writeInt(code.length);
 584             if (DEBUG) debugMessage("\tcode size = " + code.length);
 585 
 586             dos.write(code);
 587 
 588             // write exception table size
 589             dos.writeShort((short) (exceptionTableLen / 4));
 590             if (DEBUG) debugMessage("\texception table length = " + (exceptionTableLen / 4));
 591 
 592             if (exceptionTableLen != 0) {
 593                 for (int e = 0; e < exceptionTableLen; e += 4) {
 594                      dos.writeShort((short) exceptionTable.getIntAt(e));
 595                      dos.writeShort((short) exceptionTable.getIntAt(e + 1));
 596                      dos.writeShort((short) exceptionTable.getIntAt(e + 2));
 597                      dos.writeShort((short) exceptionTable.getIntAt(e + 3));
 598                 }
 599             }
 600 
 601             dos.writeShort((short)codeAttrCount);
 602             if (DEBUG) debugMessage("\tcode attribute count = " + codeAttrCount);
 603 
 604             // write LineNumberTable, if available.
 605             if (hasLineNumberTable) {
 606                 writeIndex(_lineNumberTableIndex);
 607                 dos.writeInt(lineNumberAttrLen);
 608                 dos.writeShort((short) lineNumberTable.length);
 609                 for (int l = 0; l < lineNumberTable.length; l++) {
 610                      dos.writeShort((short) lineNumberTable[l].getStartBCI());
 611                      dos.writeShort((short) lineNumberTable[l].getLineNumber());
 612                 }
 613             }
 614 
 615             // write LocalVariableTable, if available.
 616             if (hasLocalVariableTable) {
 617                 writeIndex((short) _localVariableTableIndex);


   1 /*
   2  * Copyright (c) 2002, 2012, 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.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *


 487             methodAttributeCount++;
 488 
 489         dos.writeShort(methodAttributeCount);
 490         if (DEBUG) debugMessage("\tmethod attribute count = " + methodAttributeCount);
 491 
 492         if (hasSyn) {
 493             if (DEBUG) debugMessage("\tmethod is synthetic");
 494             writeSynthetic();
 495         }
 496 
 497         if (isCodeAvailable) {
 498             byte[] code = m.getByteCode();
 499             short codeAttrCount = 0;
 500             int codeSize  = 2           /* max_stack   */ +
 501                             2           /* max_locals  */ +
 502                             4           /* code_length */ +
 503                             code.length /* code        */ +
 504                             2           /* exp. table len.  */ +
 505                             2           /* code attr. count */;
 506 
 507             boolean hasExceptionTable = m.hasExceptionTable();
 508             ExceptionTableElement[] exceptionTable = null;
 509             int exceptionTableLen = 0;
 510             if (hasExceptionTable) {
 511                 exceptionTable = m.getExceptionTable();
 512                 exceptionTableLen = exceptionTable.length;
 513                 if (DEBUG) debugMessage("\tmethod has exception table");
 514                 codeSize += exceptionTableLen /* exception table is 4-tuple array */
 515                                          * (2 /* start_pc     */ +
 516                                             2 /* end_pc       */ +
 517                                             2 /* handler_pc   */ +
 518                                             2 /* catch_type   */);
 519             }
 520 
 521             boolean hasLineNumberTable = m.hasLineNumberTable();
 522             LineNumberTableElement[] lineNumberTable = null;
 523             int lineNumberAttrLen = 0;
 524 
 525             if (hasLineNumberTable) {
 526                 if (DEBUG) debugMessage("\tmethod has line number table");
 527                 lineNumberTable = m.getLineNumberTable();
 528                 if (DEBUG) debugMessage("\t\tline table length = " + lineNumberTable.length);
 529 
 530                 lineNumberAttrLen = 2 /* line number table length         */ +
 531                            lineNumberTable.length * (2 /* start_pc */ + 2 /* line_number */);
 532 
 533                 codeSize += 2 /* line number table attr index     */ +
 534                             4 /* line number table attr length    */ +


 572 
 573             // start writing Code
 574 
 575             writeIndex(_codeIndex);
 576 
 577             dos.writeInt(codeSize);
 578             if (DEBUG) debugMessage("\tcode attribute length = " + codeSize);
 579 
 580             dos.writeShort((short) m.getMaxStack());
 581             if (DEBUG) debugMessage("\tmax stack = " + m.getMaxStack());
 582 
 583             dos.writeShort((short) m.getMaxLocals());
 584             if (DEBUG) debugMessage("\tmax locals = " + m.getMaxLocals());
 585 
 586             dos.writeInt(code.length);
 587             if (DEBUG) debugMessage("\tcode size = " + code.length);
 588 
 589             dos.write(code);
 590 
 591             // write exception table size
 592             dos.writeShort((short) exceptionTableLen);
 593             if (DEBUG) debugMessage("\texception table length = " + exceptionTableLen);
 594 
 595             if (exceptionTableLen != 0) {
 596                 for (int e = 0; e < exceptionTableLen; e++) {
 597                      dos.writeShort((short) exceptionTable[e].getStartPC());
 598                      dos.writeShort((short) exceptionTable[e].getEndPC());
 599                      dos.writeShort((short) exceptionTable[e].getHandlerPC());
 600                      dos.writeShort((short) exceptionTable[e].getCatchTypeIndex());
 601                 }
 602             }
 603 
 604             dos.writeShort((short)codeAttrCount);
 605             if (DEBUG) debugMessage("\tcode attribute count = " + codeAttrCount);
 606 
 607             // write LineNumberTable, if available.
 608             if (hasLineNumberTable) {
 609                 writeIndex(_lineNumberTableIndex);
 610                 dos.writeInt(lineNumberAttrLen);
 611                 dos.writeShort((short) lineNumberTable.length);
 612                 for (int l = 0; l < lineNumberTable.length; l++) {
 613                      dos.writeShort((short) lineNumberTable[l].getStartBCI());
 614                      dos.writeShort((short) lineNumberTable[l].getLineNumber());
 615                 }
 616             }
 617 
 618             // write LocalVariableTable, if available.
 619             if (hasLocalVariableTable) {
 620                 writeIndex((short) _localVariableTableIndex);


< prev index next >