Jfinal验证码导致虚拟机崩溃问题

开发某项目系统linux系统架构为power pc 64位系统,jre也是对应的在ibn官网下的sun自己没有,之前x86,arm等平台都能正常使用的验证码功能在这个平台上启动项目访问 通过构造器 CaptchaRender cr = new CaptchaRender() 获取验证码的时候总是导致虚拟机崩溃,具体报错信息如下:

Unhandled exception
Type=Illegal instruction vmState=0x00040000
        J9Generic_Signal_Number=00000010 Signal_Number=00000004 Error_Value=00000000 Signal_Code=00000001
        Handler1=00003FFFB60C0F10 Handler2=00003FFFB5E03CD8
        R0=00000000000C0000 R1=00003FFF9C257E80 R2=00003FFF4EFF5B10 R3=0000000000010000
        R4=0000000000010000 R5=000000000000001C R6=0000000010148A28 R7=0000000000000028
        R8=0000000000000020 R9=0000000000000000 R10=0000000000000040 R11=0000000000000080
        R12=00000000000000C0 R13=00003FFF9C2648F0 R14=0000000000734920 R15=0000000000632C00
        R16=00003FFF9CD86038 R17=FFFFFFFFFFFFFFFF R18=00000000100F417C R19=0000000000000008
        R20=0000000000000006 R21=0000000000000000 R22=000000001013C318 R23=0000000040000000
        R24=000000001013C8F0 R25=000000001013C838 R26=0000000000000164 R27=0000000000000DC4
        R28=000000001013C838 R29=0000000010145ED8 R30=00003FFF9C257FD0 R31=0000000010145E38
        NIP=00003FFF4EF830D0 MSR=000000008002F000 ORIG_GPR3=0000000000000093 CTR=00003FFFB6B90100
        LINK=00003FFF4EF7E098 XER=0000000020000000 CCR=000000004444442C SOFTE=0000000000000001
        TRAP=0000000000000700 DAR=0000000010147000 dsisr=0000000008000000 RESULT=0000000000000000
        FPR0 41f0000000000000 (f: 0.000000, d: 4.294967e+09)
        FPR1 0000000000000000 (f: 0.000000, d: 0.000000e+00)
        FPR2 43efffffffffffff (f: 4294967296.000000, d: 1.844674e+19)
        FPR3 c530000000000000 (f: 0.000000, d: -1.934281e+25)
        FPR4 40e8030000000000 (f: 0.000000, d: 4.917600e+04)
        FPR5 40fb39343ff01715 (f: 1072699136.000000, d: 1.115073e+05)
        FPR6 bfc0001886c688a0 (f: 2261158144.000000, d: -1.250029e-01)
        FPR7 bf8573ce34323da4 (f: 875707840.000000, d: -1.047479e-02)
        FPR8 3fc999999989fd15 (f: 2575957248.000000, d: 2.000000e-01)
        FPR9 bfd0000000007113 (f: 28947.000000, d: -2.500000e-01)
        FPR10 3fc249249550563d (f: 2505070080.000000, d: 1.428571e-01)
        FPR11 3fd5555555555611 (f: 1431655936.000000, d: 3.333333e-01)
        FPR12 0000000000010000 (f: 65536.000000, d: 3.237909e-319)
        FPR13 4200000000000000 (f: 0.000000, d: 8.589935e+09)
        FPR14 0000000000000000 (f: 0.000000, d: 0.000000e+00)
        FPR15 fff800000000001d (f: 29.000000, d: -nan)
        FPR16 403d000000000000 (f: 0.000000, d: 2.900000e+01)
        FPR17 403d000000000000 (f: 0.000000, d: 2.900000e+01)
        FPR18 0000000000000000 (f: 0.000000, d: 0.000000e+00)
        FPR19 0000000000000000 (f: 0.000000, d: 0.000000e+00)
        FPR20 0000000000000000 (f: 0.000000, d: 0.000000e+00)
        FPR21 0000000000000000 (f: 0.000000, d: 0.000000e+00)
        FPR22 0000000000000000 (f: 0.000000, d: 0.000000e+00)
        FPR23 0000000000000000 (f: 0.000000, d: 0.000000e+00)
        FPR24 0000000000000000 (f: 0.000000, d: 0.000000e+00)
        FPR25 0000000000000000 (f: 0.000000, d: 0.000000e+00)
        FPR26 0000000000000000 (f: 0.000000, d: 0.000000e+00)
        FPR27 0000000000000000 (f: 0.000000, d: 0.000000e+00)
        FPR28 0000000000000000 (f: 0.000000, d: 0.000000e+00)
        FPR29 0000000000000000 (f: 0.000000, d: 0.000000e+00)
        FPR30 0000000000000000 (f: 0.000000, d: 0.000000e+00)
        FPR31 0000000000000000 (f: 0.000000, d: 0.000000e+00)
        Module=/temp/jre/lib/ppc64/libt2k.so
        Module_base_address=00003FFF4EF5C000
        Target=2_90_20181106_401576 (Linux 3.12.37)
        CPU=ppc64 (4 logical CPUs) (0x68576000 RAM)
        ----------- Stack Backtrace -----------
        (0x00003FFF4EF830D0 [libt2k.so+0x270d0])
        (0x00003FFF4EF7E05C [libt2k.so+0x2205c])
        (0x00003FFF4EF7E3D4 [libt2k.so+0x223d4])
        (0x00003FFF4EF7E5F8 [libt2k.so+0x225f8])
        (0x00003FFF4EFB2A98 [libt2k.so+0x56a98])
        Java_sun_font_T2KFontScaler_initNativeScaler+0xfffafbac (0x00003FFF4EF9BE2C [libt2k.so+0x3fe2c])
        (0x00003FFFB603F524 [libj9vm29.so+0x1dd524])
        (0x00003FFFB603E76C [libj9vm29.so+0x1dc76c])
        (0x00003FFFB5EDEC94 [libj9vm29.so+0x7cc94])
        (0x00003FFFB5F76E34 [libj9vm29.so+0x114e34])
        (0x00003FFFB5F26580 [libj9vm29.so+0xc4580])
        (0x00003FFFB5F26DD4 [libj9vm29.so+0xc4dd4])
        (0x00003FFFB5113534 [libjclse7b_29.so+0x98534])
        JVM_NewInstanceFromConstructor+0xfffa2e04 (0x00003FFFB6130614 [libjvm.so+0x39614])
        JVM_NewInstanceFromConstructor+0xfffcdf88 (0x00003FFFB6A8D1F8 [libjvm.so+0xf1f8])
        Java_sun_reflect_NativeConstructorAccessorImpl_newInstance0+0xfffd35f0 (0x00003FFFB4064888 [libjava.so+0x13888])
        (0x00003FFFB603F524 [libj9vm29.so+0x1dd524])
        (0x00003FFFB603E76C [libj9vm29.so+0x1dc76c])
        (0x00003FFFB5EDEC94 [libj9vm29.so+0x7cc94])
        (0x00003FFFB5F76E34 [libj9vm29.so+0x114e34])
        (0x00003FFFB5F22630 [libj9vm29.so+0xc0630])
        (0x00003FFFB5F99120 [libj9vm29.so+0x137120])
        (0x00003FFFB5D92950 [libj9prt29.so+0x4c950])
        (0x00003FFFB5F98ED4 [libj9vm29.so+0x136ed4])
        (0x00003FFFB5E3AF4C [libj9thr29.so+0xcf4c])
        (0x00003FFFB6CE6680 [libpthread.so.0+0xb680])
        clone+0xfff67688 (0x00003FFFB6BF1398 [libc.so.6+0x119398])
        ---------------------------------------
        JVMDUMP039I Processing dump event "gpf", detail "" at 2018/12/11 15:05:48 - please wait.
        JVMDUMP032I JVM requested System dump using '/temp/server/core.20181211.150548.5376.0001.dmp' in response to an event
        JVMDUMP010I System dump written to /temp/server/core.20181211.150548.5376.0001.dmp
        JVMDUMP032I JVM requested Java dump using '/temp/server/javacore.20181211.150548.5376.0002.txt' in response to an event
        JVMDUMP010I Java dump written to /temp/server/javacore.20181211.150548.5376.0002.txt
        JVMDUMP032I JVM requested Snap dump using '/temp/server/Snap.20181211.150548.5376.0003.trc' in response to an event
        JVMDUMP010I Snap dump written to /temp/server/Snap.20181211.150548.5376.0003.trc
        JVMDUMP007I JVM Requesting JIT dump using '/temp/server/jitdump.20181211.150548.5376.0004.dmp'
        JVMDUMP010I JIT dump written to /temp/server/jitdump.20181211.150548.5376.0004.dmp
        JVMDUMP013I Processed dump event "gpf", detail "".

断点跟踪是运行至以下代码中的g.drawString所导致——

protected void drawGraphic(String randomString, BufferedImage image) {
    Graphics2D g = image.createGraphics();
    g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR);
    g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
    g.setColor(this.getRandColor(210, 250));
    g.fillRect(0, 0, 108, 40);
    Color color = null;

    int i;
    for(i = 0; i < 20; ++i) {
        color = this.getRandColor(120, 200);
        g.setColor(color);
        String rand = String.valueOf(charArray[random.nextInt(charArray.length)]);
        g.drawString(rand, random.nextInt(108), random.nextInt(40));
        color = null;
    }
     .....
}

请问波总,这是什么原因导致的呢,网上查到jfinal的验证码似乎有些问题,如果无法解决或找不到原因,那我只能尝试另外的方法实现验证码了。很期待问题解决,谢谢。

评论区

JFinal

2018-12-11 16:22

可能是这个平台上的 JVM 的这个 API 有 bug

建议自己写一个 MyCaptchaRender extends Render

然后用的时候这样:
render(new MyCaptchaRender(...));

网上很多验证码代码,放入 MyCaptchaRender 即可

陈本布衣

2018-12-11 17:28

实现render方法后没有思路,还请波总明示啊

JFinal

2018-12-11 17:32

@陈本布衣 照猫画虎,得到 response.getOutputStream() 往这个 OutputStream 中扔数据就行

扔出去的数据就是你的验证码图片,而生成验证码图片的代码满大街都是

没牙的小朋友

2018-12-11 23:43

曾经遇到过这个问题,不过好像是老版本,不清楚用的哪个版本的jfinal,不知道哪个版本之前验证码的字体名随机数组中使用了linux没有的字体,导致jvm崩溃。后来好像报过bug,波总改了。我在每改之前是判断操作系统类型,根据操作系统类型初始化字体数组中的字体名。linux我用的Font.SERIF之类的 你可以看看源码

没牙的小朋友

2018-12-11 23:44

可以看看我之前的反馈。http://www.jfinal.com/feedback/3494

陈本布衣

2018-12-12 09:04

谢谢波总和没牙的小朋友,社区还蛮活跃的嘛,我先试着解决下 吧;最开始断点跟踪我也怀疑是系统字体不支持,我用的是3.1的版本,想换3.5jar包,结果替换后有些调用的接口有改变,没法完全适应,就罢了

JFinal

2018-12-13 21:56

@陈本布衣 3.1 到 3.5 有变动的地方基本就是改改类名改改方法名,5 分钟内完成升级,值得拥有

热门反馈

扫码入社