如何计算java中执行的字节码数量 [英] How to count number of bytecodes executed in java

查看:185
本文介绍了如何计算java中执行的字节码数量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要参加麻省理工学院的电池竞赛。参赛者编写的程序可以控制相互对抗的机器人。问题在于你的机器人只能在一个回合中执行一定数量的字节码(去年每回合10000次)。现在,一个简单的循环
喜欢

I'm going to enter MIT's battlecode competition. The entrants write programs that control robots that fight each other. The catch is that your robots are limited to executing a certain amount of bytecode in a turn (last year it was 10000 per turn). Now, a simple loop like

(int i=0; i<100; i++){
// do nothing
}

根据他们的软件使用大约400字节码(大概是
(2字节码用于递增i加2字节码
用于检查i< 100)* 100 = 400字节码)所以我们必须编写非常严格的代码。因此,当我尝试一些不同的导航算法时,重要的是我能够弄清楚我的代码使用了多少字节码 - 我该怎么做?

uses, according to their software, approximately 400 bytecode (presumably something like (2 bytecode for incrementing i plus 2 bytecode for checking if i<100) * 100 = 400 bytecode) so we have to write very tight code. Hence, as I try out some different navigation algorithms its important that I be able to figure out how much bytecode my code is using -- how can I do this?

(有可能 - 他们这样做,我只是不确定如何!而且,他们必须阻止JIT以某种方式进入游戏。我知道每个机器人在一个单独的线程中运行,所以我确定
答案涉及某种我不知道的线程技巧。)

(It IS possible -- they do it, I'm just not sure how! Also, they must stop the JIT from coming into play somehow. I know that each robot is run in a separate Thread, so I'm sure the answer involves some sort of Thread trickery I don't know about.)

推荐答案

查看他们的源代码,他们使用asm字节码操纵器 http://asm.ow2.org/ 进行计数。

Looking over their source code, they use the asm bytecode manipulator http://asm.ow2.org/ to do the counting.

这篇关于如何计算java中执行的字节码数量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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