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 23 * questions. 24 */ 25 26 package jdk.nashorn.internal.ir.debug; 27 28 import static jdk.nashorn.internal.runtime.linker.NashornCallSiteDescriptor.CALLSITE_PROGRAM_POINT_SHIFT; 29 import static jdk.nashorn.internal.runtime.linker.NashornCallSiteDescriptor.FLAGS_MASK; 30 31 import java.io.File; 32 import java.io.FileNotFoundException; 33 import java.io.FileOutputStream; 34 import java.io.PrintWriter; 35 import java.util.HashMap; 36 import java.util.HashSet; 37 import java.util.Iterator; 38 import java.util.LinkedHashSet; 39 import java.util.List; 40 import java.util.Map; 41 import java.util.Set; 42 import jdk.internal.org.objectweb.asm.Attribute; 43 import jdk.internal.org.objectweb.asm.Handle; 44 import jdk.internal.org.objectweb.asm.Label; 45 import jdk.internal.org.objectweb.asm.Opcodes; 46 import jdk.internal.org.objectweb.asm.Type; 47 import jdk.internal.org.objectweb.asm.signature.SignatureReader; 48 import jdk.internal.org.objectweb.asm.util.Printer; 49 import jdk.internal.org.objectweb.asm.util.TraceSignatureVisitor; 50 import jdk.nashorn.internal.runtime.ScriptEnvironment; 485 addText(sb); 486 } 487 488 @Override 489 public void visitMethodInsn(final int opcode, final String owner, final String name, final String desc, final boolean itf) { 490 final StringBuilder sb = new StringBuilder(); 491 appendOpcode(sb, opcode).append(' '); 492 appendDescriptor(sb, INTERNAL_NAME, owner); 493 sb.append('.').append(name); 494 appendDescriptor(sb, METHOD_DESCRIPTOR, desc); 495 sb.append('\n'); 496 addText(sb); 497 } 498 499 @Override 500 public void visitInvokeDynamicInsn(final String name, final String desc, final Handle bsm, final Object... bsmArgs) { 501 final StringBuilder sb = new StringBuilder(); 502 503 appendOpcode(sb, Opcodes.INVOKEDYNAMIC).append(' '); 504 final boolean isNashornBootstrap = isNashornBootstrap(bsm); 505 if (isNashornBootstrap) { 506 sb.append(NashornCallSiteDescriptor.getOperationName((Integer)bsmArgs[0])); 507 final String decodedName = NameCodec.decode(name); 508 if (!decodedName.isEmpty()) { 509 sb.append(':').append(decodedName); 510 } 511 } else { 512 sb.append(name); 513 } 514 appendDescriptor(sb, METHOD_DESCRIPTOR, desc); 515 final int len = sb.length(); 516 for (int i = 0; i < 80 - len ; i++) { 517 sb.append(' '); 518 } 519 sb.append(" ["); 520 appendHandle(sb, bsm); 521 if (bsmArgs.length == 0) { 522 sb.append("none"); 523 } else { 524 for (final Object cst : bsmArgs) { 525 if (cst instanceof String) { 526 appendStr(sb, (String)cst); 527 } else if (cst instanceof Type) { 528 sb.append(((Type)cst).getDescriptor()).append(".class"); 529 } else if (cst instanceof Handle) { 530 appendHandle(sb, (Handle)cst); 531 } else if (cst instanceof Integer && isNashornBootstrap) { 532 final int c = (Integer)cst; 533 final int pp = c >> CALLSITE_PROGRAM_POINT_SHIFT; 534 if (pp != 0) { 535 sb.append(" pp=").append(pp); 536 } 537 sb.append(NashornCallSiteDescriptor.toString(c & FLAGS_MASK)); 538 } else { 539 sb.append(cst); 540 } 541 sb.append(", "); 542 } 543 sb.setLength(sb.length() - 2); 544 } 545 546 sb.append("]\n"); 547 addText(sb); 548 } 549 550 private static boolean isNashornBootstrap(final Handle bsm) { 551 return "bootstrap".equals(bsm.getName()) && BOOTSTRAP_CLASS_NAME.equals(bsm.getOwner()); 552 } 553 554 private static boolean noFallThru(final int opcode) { 555 switch (opcode) { 556 case Opcodes.GOTO: 557 case Opcodes.ATHROW: 558 case Opcodes.ARETURN: 559 case Opcodes.IRETURN: 560 case Opcodes.LRETURN: 561 case Opcodes.FRETURN: 562 case Opcodes.DRETURN: 563 return true; 564 default: 565 return false; 566 } 567 } 568 569 private void checkNoFallThru(final int opcode, final String to) { 570 if (noFallThru(opcode)) { 571 graph.setNoFallThru(currentBlock); | 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 23 * questions. 24 */ 25 26 package jdk.nashorn.internal.ir.debug; 27 28 import java.io.File; 29 import java.io.FileNotFoundException; 30 import java.io.FileOutputStream; 31 import java.io.PrintWriter; 32 import java.util.HashMap; 33 import java.util.HashSet; 34 import java.util.Iterator; 35 import java.util.LinkedHashSet; 36 import java.util.List; 37 import java.util.Map; 38 import java.util.Set; 39 import jdk.internal.org.objectweb.asm.Attribute; 40 import jdk.internal.org.objectweb.asm.Handle; 41 import jdk.internal.org.objectweb.asm.Label; 42 import jdk.internal.org.objectweb.asm.Opcodes; 43 import jdk.internal.org.objectweb.asm.Type; 44 import jdk.internal.org.objectweb.asm.signature.SignatureReader; 45 import jdk.internal.org.objectweb.asm.util.Printer; 46 import jdk.internal.org.objectweb.asm.util.TraceSignatureVisitor; 47 import jdk.nashorn.internal.runtime.ScriptEnvironment; 482 addText(sb); 483 } 484 485 @Override 486 public void visitMethodInsn(final int opcode, final String owner, final String name, final String desc, final boolean itf) { 487 final StringBuilder sb = new StringBuilder(); 488 appendOpcode(sb, opcode).append(' '); 489 appendDescriptor(sb, INTERNAL_NAME, owner); 490 sb.append('.').append(name); 491 appendDescriptor(sb, METHOD_DESCRIPTOR, desc); 492 sb.append('\n'); 493 addText(sb); 494 } 495 496 @Override 497 public void visitInvokeDynamicInsn(final String name, final String desc, final Handle bsm, final Object... bsmArgs) { 498 final StringBuilder sb = new StringBuilder(); 499 500 appendOpcode(sb, Opcodes.INVOKEDYNAMIC).append(' '); 501 final boolean isNashornBootstrap = isNashornBootstrap(bsm); 502 final boolean isNashornMathBootstrap = isNashornMathBootstrap(bsm); 503 if (isNashornBootstrap) { 504 sb.append(NashornCallSiteDescriptor.getOperationName((Integer)bsmArgs[0])); 505 final String decodedName = NameCodec.decode(name); 506 if (!decodedName.isEmpty()) { 507 sb.append(':').append(decodedName); 508 } 509 } else { 510 sb.append(name); 511 } 512 appendDescriptor(sb, METHOD_DESCRIPTOR, desc); 513 final int len = sb.length(); 514 for (int i = 0; i < 80 - len ; i++) { 515 sb.append(' '); 516 } 517 sb.append(" ["); 518 appendHandle(sb, bsm); 519 if (bsmArgs.length == 0) { 520 sb.append("none"); 521 } else { 522 for (final Object cst : bsmArgs) { 523 if (cst instanceof String) { 524 appendStr(sb, (String)cst); 525 } else if (cst instanceof Type) { 526 sb.append(((Type)cst).getDescriptor()).append(".class"); 527 } else if (cst instanceof Handle) { 528 appendHandle(sb, (Handle)cst); 529 } else if (cst instanceof Integer && isNashornBootstrap) { 530 NashornCallSiteDescriptor.appendFlags((Integer) cst, sb); 531 } else if (cst instanceof Integer && isNashornMathBootstrap) { 532 sb.append(" pp=").append(cst); 533 } else { 534 sb.append(cst); 535 } 536 sb.append(", "); 537 } 538 sb.setLength(sb.length() - 2); 539 } 540 541 sb.append("]\n"); 542 addText(sb); 543 } 544 545 private static boolean isNashornBootstrap(final Handle bsm) { 546 return "bootstrap".equals(bsm.getName()) && BOOTSTRAP_CLASS_NAME.equals(bsm.getOwner()); 547 } 548 549 private static boolean isNashornMathBootstrap(final Handle bsm) { 550 return "mathBootstrap".equals(bsm.getName()) && BOOTSTRAP_CLASS_NAME.equals(bsm.getOwner()); 551 } 552 553 private static boolean noFallThru(final int opcode) { 554 switch (opcode) { 555 case Opcodes.GOTO: 556 case Opcodes.ATHROW: 557 case Opcodes.ARETURN: 558 case Opcodes.IRETURN: 559 case Opcodes.LRETURN: 560 case Opcodes.FRETURN: 561 case Opcodes.DRETURN: 562 return true; 563 default: 564 return false; 565 } 566 } 567 568 private void checkNoFallThru(final int opcode, final String to) { 569 if (noFallThru(opcode)) { 570 graph.setNoFallThru(currentBlock); |