package java.lang;
public class Object {
private static native void registerNatives();
//创建对象时,先调用静态代码块(即registerNatives()方法),。native关键字表示该方法不是由java语言编写,
//而是通过C/C++来完成的,并被编译成.dll 之后才由Java调用,方法的具体实现是在dll文件中。
//registerNatives()方法主要作用就是将C/C++中的方法映射到Java中的native方法,实现方法命名的解耦。
//jvm类加载是基于操作系统c上来的,得先加载
static {
registerNatives();
}
//返回了这个对象的运行时类。返回的Class对象是正被静态同步方法锁住的对象当getClass()方法被执行时,实际结
//果类型是Class<? extends |X|> 其中|X|表示静态类型。例如,这个代码片段不需要强制转换。
public final native Class<?> getClass();
public native int hashCode();
public boolean equals(Object obj) {
return (this == obj);
}
protected native Object clone() throws CloneNotSupportedException;
public String toString() {
return getClass().getName() + "@" + Integer.toHexString(hashCode());
}
public final native void notify();
public final native void notifyAll();
public final native void wait(long timeout) throws InterruptedException;
public final void wait(long timeout, int nanos) throws InterruptedException {
if (timeout < 0) {
throw new IllegalArgumentException("timeout value is negative");
}
if (nanos < 0 || nanos > 999999) {
throw new IllegalArgumentException(
"nanosecond timeout value out of range");
}
if (nanos > 0) {
timeout++;
}
wait(timeout);
}
public final void wait() throws InterruptedException {
wait(0);
}
protected void finalize() throws Throwable { }
}
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;