修改openjdk17 java/lang/String.java 类源码,增加一个native本地方法打印固定字符串功能
java/lang/String.java 新增加native方法
public native void printStringTable();
##图片
##/home/yym/openjdk17/jdk17-master/src/hotspot/share/include/jvm.h文件增加方法
//yym-gaizao
JNIEXPORT void JNICALL
JVM_String_printStringTable(JNIEnv *env, jstring str);
##src/hotspot/share/prims/jvm.cpp文件增加方法
//yym-gaizao
JVM_ENTRY(void, JVM_String_printStringTable(JNIEnv *env, jstring str))
std::cout << "@@@@yym%%%%method address " << "" << "----begin" << std::endl;
JVM_END
##/home/yym/openjdk17/jdk17-master/build/linux-x86_64-server-slowdebug/support/headers/java.base/java_lang_String.h增加方法
//yym-gaizao
/*
* Class: java_lang_String
* Method: printStringTable
* Signature: ()V
*/
JNIEXPORT void JNICALL Java_java_lang_String_printStringTable
(JNIEnv *, jobject);
##src/java.base/share/native/libjava/String.c增加方法
//yym-gaizao
JNIEXPORT void JNICALL
Java_java_lang_String_printStringTable(JNIEnv *env, jobject this)
{
JVM_String_printStringTable(env, this);
}
##/home/yym/openjdk17/jdk17-master/make/data/hotspot-symbols/symbols-unix符号表增加JVM_String_printStringTable方法符号
# yym-gaizao
JVM_String_printStringTable
##编译openjdk17源码
yym@yym:~/javaTest$ cd /home/yym/openjdk17/jdk17-master/
yym@yym:~/openjdk17/jdk17-master$ make CONF=linux-x86_64-server-slowdebug
##编写编译StringTableMain.java类并运行
yym@yym:~/javaTest$ /home/yym/openjdk17/jdk17-master/build/linux-x86_64-server-slowdebug/jdk/bin/javac StringTableMain.java
yym@yym:~/javaTest$ /home/yym/openjdk17/jdk17-master/build/linux-x86_64-server-slowdebug/jdk/bin/java StringTableMain
@@@@yym%%%%method address ----begin
------------------------------------
yyyyyyyyyyyyyyyyy
ddddddddddddddddddddddddddddddd
yym@yym:~/javaTest$ cat StringTableMain.java
public class StringTableMain {
public static final String yyyyyyyyyyyyyyyyy="yyyyyyyyyyyyyyyyy";
public static void main(String[] args) {
"-----------yym----------".intern();
"-----------ddd----------".printStringTable();
String ddddddddddddddddddddddddddddddd="ddddddddddddddddddddddddddddddd";
System.out.println("------------------------------------");
System.out.println(yyyyyyyyyyyyyyyyy);
System.out.println(ddddddddddddddddddddddddddddddd);
}
}