本文介绍了Java本机方法源代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在哪里可以下载java原生方法源代码?例如,我想知道 System.arraycopy()
的源代码,但我找不到。
Where can I download the java native method source code? For example, I want to know the source code of System.arraycopy()
, but I can't find.
推荐答案
您可以在这里下载OpenJdk源代码。
You can download OpenJdk source code here.
在文件夹 jdk\src\share
中,您可以获得源代码。
In the folder jdk\src\share
you can get source code.
jdk\src\share\\\
是用c和c ++编写的natice方法源。
ative
jdk\src\share\native
is the natice method souce write in c and c++.
-
jdk\src\linux
linux的来源。 -
jdk\src\windows
Windows的来源。 -
jdk\src\solaris
来自solaris的源。 -
jd\src\share
常见来源。
jdk\src\linux
source for linux.jdk\src\windows
source for windows.jdk\src\solaris
souce for solaris.jd\src\share
common source.
例如:System.arrayCopy();
eg: System.arrayCopy();
int file hotspot\src\ share \vm\oops\objArrayKlass.cpp
第168行:
int file hotspot\src\share\vm\oops\objArrayKlass.cpp
line 168:
void objArrayKlass::copy_array(arrayOop s, int src_pos, arrayOop d,
int dst_pos, int length, TRAPS) {
assert(s->is_objArray(), "must be obj array");
if (!d->is_objArray()) {
THROW(vmSymbols::java_lang_ArrayStoreException());
}
// Check is all offsets and lengths are non negative
if (src_pos < 0 || dst_pos < 0 || length < 0) {
THROW(vmSymbols::java_lang_ArrayIndexOutOfBoundsException());
}
// Check if the ranges are valid
if ( (((unsigned int) length + (unsigned int) src_pos) > (unsigned int) s->length())
|| (((unsigned int) length + (unsigned int) dst_pos) > (unsigned int) d->length()) ) {
THROW(vmSymbols::java_lang_ArrayIndexOutOfBoundsException());
}
// Special case. Boundary cases must be checked first
// This allows the following call: copy_array(s, s.length(), d.length(), 0).
// This is correct, since the position is supposed to be an 'in between point', i.e., s.length(),
// points to the right of the last element.
if (length==0) {
return;
}
if (UseCompressedOops) {
narrowOop* const src = objArrayOop(s)->obj_at_addr<narrowOop>(src_pos);
narrowOop* const dst = objArrayOop(d)->obj_at_addr<narrowOop>(dst_pos);
do_copy<narrowOop>(s, src, d, dst, length, CHECK);
} else {
oop* const src = objArrayOop(s)->obj_at_addr<oop>(src_pos);
oop* const dst = objArrayOop(d)->obj_at_addr<oop>(dst_pos);
do_copy<oop> (s, src, d, dst, length, CHECK);
}
}
这篇关于Java本机方法源代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!