1package java.lang; 2public class Object { 3 private static native void registerNatives(); 4 //创建对象时,先调用静态代码块(即registerNatives()方法),。native关键字表示该方法不是由java语言编写, 5 //而是通过C/C++来完成的,并被编译成.dll 之后才由Java调用,方法的具体实现是在dll文件中。 6 //registerNatives()方法主要作用就是将C/C++中的方法映射到Java中的native方法,实现方法命名的解耦。 7 //jvm类加载是基于操作系统c上来的,得先加载 8 static { 9 registerNatives(); 10 } 11 12 //返回了这个对象的运行时类。返回的Class对象是正被静态同步方法锁住的对象当getClass()方法被执行时,实际结 13 //果类型是Class<? extends |X|> 其中|X|表示静态类型。例如,这个代码片段不需要强制转换。 14 public final native Class<?> getClass(); 15 16 17 public native int hashCode(); 18 19 20 public boolean equals(Object obj) { 21 return (this == obj); 22 } 23 24 25 protected native Object clone() throws CloneNotSupportedException; 26 27 28 public String toString() { 29 return getClass().getName() + "@" + Integer.toHexString(hashCode()); 30 } 31 32 33 public final native void notify(); 34 35 36 public final native void notifyAll(); 37 38 39 public final native void wait(long timeout) throws InterruptedException; 40 41 public final void wait(long timeout, int nanos) throws InterruptedException { 42 if (timeout < 0) { 43 throw new IllegalArgumentException("timeout value is negative"); 44 } 45 46 if (nanos < 0 || nanos > 999999) { 47 throw new IllegalArgumentException( 48 "nanosecond timeout value out of range"); 49 } 50 51 if (nanos > 0) { 52 timeout++; 53 } 54 55 wait(timeout); 56 } 57 58 59 public final void wait() throws InterruptedException { 60 wait(0); 61 } 62 63 64 protected void finalize() throws Throwable { } 65}
package com.qf58.exec.ratelimiter; /** _ * @version 1.0 _ * @author: 刘源源 _ * @date:_ _2021-02-20 21:56 _ */ public class ObjectTest implements Cloneable{ public static void main(String[] args) { try { new ObjectTest().clone(); } catch (CloneNotSupportedException e) { e.printStackTrace(); } String s = "hello"; Integer t = 0; System.out.println(s.getClass()); System.out.println(t.getClass()); } }
对于ObjectTest类没有继承Object,是怎么织入得呢
检验了jdk1.8,jdk1.7,jdk1.6 jdk1.6 来说是由继承Object 超级父类的
找到对应的这个java文件
cmd 然后
javap Object.class >Object1.8.txt
将反编译后的文本输入到txt里面
Object ctrl + 鼠标左键进入Object类里面,ctrl+f12 查看方法
对于hashcode
可以研究下hashcode底层源码,native方法,调用底层库
https://gitee.com/chen0218/openjdk8/repository/archive/master.zip
可以从这个下载openjdk源码
解压后,找到F:\java\openjdk8\openjdk\hotspot\src\share\vm\prims

JVM_ENTRY(jint, JVM_IHashCode(JNIEnv* env, jobject handle)) JVMWrapper("JVM_IHashCode"); // as implemented in the classic virtual machine; return 0 if object is NULL return handle == NULL ? 0 : ObjectSynchronizer::FastHashCode (THREAD, JNIHandles::resolve_non_null(handle)) ; JVM_END
JVM_ENTRY(void, JVM_MonitorWait(JNIEnv* env, jobject handle, jlong ms)) JVMWrapper("JVM_MonitorWait"); Handle obj(THREAD, JNIHandles::resolve_non_null(handle)); JavaThreadInObjectWaitState jtiows(thread, ms != 0); if (JvmtiExport::should_post_monitor_wait()) { JvmtiExport::post_monitor_wait((JavaThread *)THREAD, (oop)obj(), ms); } ObjectSynchronizer::wait(obj, ms, CHECK); JVM_END
JVM_ENTRY(void, JVM_MonitorNotify(JNIEnv* env, jobject handle)) JVMWrapper("JVM_MonitorNotify"); Handle obj(THREAD, JNIHandles::resolve_non_null(handle)); ObjectSynchronizer::notify(obj, CHECK); JVM_END
JVM_ENTRY(void, JVM_MonitorNotifyAll(JNIEnv* env, jobject handle)) JVMWrapper("JVM_MonitorNotifyAll"); Handle obj(THREAD, JNIHandles::resolve_non_null(handle)); ObjectSynchronizer::notifyall(obj, CHECK); JVM_END
JVM_ENTRY(jobject, JVM_Clone(JNIEnv* env, jobject handle)) JVMWrapper("JVM_Clone"); Handle obj(THREAD, JNIHandles::resolve_non_null(handle)); const KlassHandle klass (THREAD, obj->klass()); JvmtiVMObjectAllocEventCollector oam;