为什么一些java库没有编译调试信息 [英] Why are some java libraries compiled without debugging information

查看:121
本文介绍了为什么一些java库没有编译调试信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近注意到有一些java库(JDK,joda时间,iText)没有一些/所有的调试信息编译。或者缺少本地变量信息,或者缺少本地变量信息和行号。

I've noticed recently that there's a few java libs (the JDK, joda time, iText) that compile without some/all of the debugging information. Either the local variable info is missing, or the both the local variable info and line numbers are missing.

有什么原因吗?我意识到它使编译代码更大,但我不相信这是一个特别大的考虑。

Is there any reason for this? I realise it makes compiled code larger but I don't believe that's a particular large consideration. Or is it just building with the default compile options?

推荐答案

默认的编译选项不包括调试信息,你必须具体告诉编译器包含它。有大多数人忽略它的原因有几个:

The default compile options don't include debugging information, you must specifically tell the compiler to include it. There are several reasons why most people omit it:


  • 一些库用于嵌入式系统(如手机)。直到最近,每一点都算。今天,大多数移动设备比1985年的所有计算机都有更多的内存;)

  • 编译时使用调试活动,代码运行速度降低5%。

  • 今天的高级开发人员诞生于64KB的内存是巨大的时候。昨天,我在地窖里给我的服务器增加了另一个2TB的驱动器。这是25年来7个数量级。人类需要更多时间来调整。

正如John指出的,Java字节码现在还没有进行优化。因此,类文件的输出对于这两种情况将是相同的(只有具有调试信息的类文件将更大)。代码在JIT中在运行时被优化,这允许运行时优化CPU,存储器(数量和布局)等的代码。

As John pointed out, Java bytecode isn't optimized (much) anymore today. So the output of the class files will be the same for both cases (only the class file with debug information will be bigger). The code is optimized in the JIT at runtime which allows the runtime to optimize the code for the CPU, memory (amount and layout), etc.

提到的5%是当您运行代码并添加命令行选项以允许远程调试器附加到进程。如果您没有启用远程调试,则没有惩罚(除了类加载,但只发生一次)。

The mentioned 5% penalty is when you run the code and add the command line options to allow a remote debugger to attach to the process. If you don't enable remote debugging, there is no penalty (except for class loading but that happens only once).

这篇关于为什么一些java库没有编译调试信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆