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

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

问题描述

我最近注意到有一些 Java 库(JDK、joda time、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 RAM 巨大的时代.昨天,我在地下室的服务器上又添加了一个 2TB 驱动器.这是 25 年内的 7 个数量级.人类需要更多时间来适应.

正如约翰指出的那样,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天全站免登陆