都是“魔术"吗? JVM上标记为“本地"的方法? [英] Are all the "Magic" methods on the JVM marked as Native?

查看:92
本文介绍了都是“魔术"吗? JVM上标记为“本地"的方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

魔术"是指具有纯Java中未表达的语义的方法.

By "Magic" I mean the methods which have semantics which are not expressed in pure Java.

我知道所有native方法都是魔术,因为它们的实现是由基础运行时提供的,而不是由Java字节码提供的.

I know all native methods are magic, in that their implementation is provided by the underlying runtime and not by Java bytecodes.

相反是真的吗?是所有魔术方法native,还是显然有一些魔术方法是在纯Java中实现的,但是在某些JVM特殊外壳的帮助下?

Is the reverse true? Are all magic methods native, or are there some magic methods apparently implemented in pure Java, but with some extra help from some JVM-special-casing?

用例是我想通过检测Java的字节码来修改Java的语义.所有这些魔术方法都是特殊情况,我将不得不以某种方式来处理. native都是显而易见的,但是我想知道是否有任何未标记的魔术方法需要我注意和特殊情况.

The use case is that I want to modify the semantics of Java by instrumenting its bytecodes. All these magic methods are special cases which I will have to handle some way or another. The native ones are all obvious, but I was wondering if there are any unmarked magic methods I have to watch out and special case for.

推荐答案

不幸的是,本机方法之外还存在魔术"方法.看一下固有方法-这些方法是JIT已知的,JIT在编译方法时会使用手动滚动实现,其中包括大量调用的方法,例如String.indexOf,

Unfortunately there are "magic" methods outside of native methods. Take a look at intrinsic methods - these methods are known to the JIT, which uses hand rolled implementations when a method is compiled, and include heavily called methods such as String.indexOf, Integer.numberOfLeadingZeros, etc.

在Intrinsics下查看此处,了解一些详细信息以及如何确定您的JVM内建了哪些方法.我不确定注入字节码是否会关闭泛化,但是您可以使用DisableIntrinsic XX选项来禁用选定的内在函数.

Take a look at here, under Intrinsics, for some details and how to determine which methods are intrinsified on your JVM. I'm not sure if injecting bytecode will turn off intrisification, but there is a DisableIntrinsic XX option you can use to disable selected intrinsics.

这篇关于都是“魔术"吗? JVM上标记为“本地"的方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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