< prev index next >

src/java.base/share/classes/java/lang/invoke/StringConcatFactory.java

Print this page

        

*** 955,996 **** Exactness checks compare the final StringBuilder.capacity() with a resulting String.length(). If these values disagree, that means StringBuilder had to perform storage trimming, which defeats the purpose of exact strategies. */ mv.visitInsn(DUP); mv.visitMethodInsn( INVOKEVIRTUAL, "java/lang/StringBuilder", "capacity", "()I", false ); ! mv.visitIntInsn(ISTORE, 0); mv.visitMethodInsn( INVOKEVIRTUAL, "java/lang/StringBuilder", "toString", "()Ljava/lang/String;", false ); - mv.visitInsn(DUP); - mv.visitMethodInsn( INVOKEVIRTUAL, "java/lang/String", "length", "()I", false ); - mv.visitIntInsn(ILOAD, 0); - Label l0 = new Label(); mv.visitJumpInsn(IF_ICMPEQ, l0); mv.visitTypeInsn(NEW, "java/lang/AssertionError"); mv.visitInsn(DUP); --- 955,1008 ---- Exactness checks compare the final StringBuilder.capacity() with a resulting String.length(). If these values disagree, that means StringBuilder had to perform storage trimming, which defeats the purpose of exact strategies. */ + /* + The logic for this check is as follows: + + Stack before: Op: + (SB) dup, dup + (SB, SB, SB) capacity() + (int, SB, SB) swap + (SB, int, SB) toString() + (S, int, SB) length() + (int, int, SB) if_icmpeq + (SB) <end> + + Note that it leaves the same StringBuilder on exit, like the one on enter. + */ + + mv.visitInsn(DUP); mv.visitInsn(DUP); mv.visitMethodInsn( INVOKEVIRTUAL, "java/lang/StringBuilder", "capacity", "()I", false ); ! mv.visitInsn(SWAP); mv.visitMethodInsn( INVOKEVIRTUAL, "java/lang/StringBuilder", "toString", "()Ljava/lang/String;", false ); mv.visitMethodInsn( INVOKEVIRTUAL, "java/lang/String", "length", "()I", false ); Label l0 = new Label(); mv.visitJumpInsn(IF_ICMPEQ, l0); mv.visitTypeInsn(NEW, "java/lang/AssertionError"); mv.visitInsn(DUP);
*** 1001,1019 **** "(Ljava/lang/Object;)V", false); mv.visitInsn(ATHROW); mv.visitLabel(l0); ! } else { mv.visitMethodInsn( INVOKEVIRTUAL, "java/lang/StringBuilder", "toString", "()Ljava/lang/String;", false ); - } mv.visitInsn(ARETURN); mv.visitMaxs(-1, -1); mv.visitEnd(); --- 1013,1031 ---- "(Ljava/lang/Object;)V", false); mv.visitInsn(ATHROW); mv.visitLabel(l0); ! } ! mv.visitMethodInsn( INVOKEVIRTUAL, "java/lang/StringBuilder", "toString", "()Ljava/lang/String;", false ); mv.visitInsn(ARETURN); mv.visitMaxs(-1, -1); mv.visitEnd();
< prev index next >