Skip to main content

100 posts tagged with "java"

View All Tags

dubbo-rpc

· 4 min read
doInvoke:92, DubboInvoker (org.apache.dubbo.rpc.protocol.dubbo)
invoke:173, AbstractInvoker (org.apache.dubbo.rpc.protocol)
invoke:52, AsyncToSyncInvoker (org.apache.dubbo.rpc.protocol)
invoke:78, ListenerInvokerWrapper (org.apache.dubbo.rpc.listener)
invoke:91, MonitorFilter (org.apache.dubbo.monitor.support)
invoke:61, FilterNode (org.apache.dubbo.rpc.protocol)
invoke:52, FutureFilter (org.apache.dubbo.rpc.protocol.dubbo.filter)
invoke:61, FilterNode (org.apache.dubbo.rpc.protocol)
invoke:69, ConsumerContextFilter (org.apache.dubbo.rpc.filter)
invoke:61, FilterNode (org.apache.dubbo.rpc.protocol)
invoke:56, InvokerWrapper (org.apache.dubbo.rpc.protocol)
doInvoke:79, FailoverClusterInvoker (org.apache.dubbo.rpc.cluster.support)
invoke:265, AbstractClusterInvoker (org.apache.dubbo.rpc.cluster.support)
intercept:47, ClusterInterceptor (org.apache.dubbo.rpc.cluster.interceptor)
invoke:92, AbstractCluster$InterceptorInvokerNode (org.apache.dubbo.rpc.cluster.support.wrapper)
invoke:93, MockClusterInvoker (org.apache.dubbo.rpc.cluster.support.wrapper)
invoke:170, MigrationInvoker (org.apache.dubbo.registry.client.migration)
invoke:96, InvokerInvocationHandler (org.apache.dubbo.rpc.proxy)
testRpc:-1, proxy1 (org.apache.dubbo.common.bytecode)
testRpc:30, ThirdDubboManagerImpl (com.patpat.mms.mdp.biz.engine.dependencies.api.impl)
testRpc:41, PushTest (com.patpat.mms.mdp.biz.engine.rest)
invoke0:-1, NativeMethodAccessorImpl (jdk.internal.reflect)
invoke:62, NativeMethodAccessorImpl (jdk.internal.reflect)
invoke:43, DelegatingMethodAccessorImpl (jdk.internal.reflect)
invoke:566, Method (java.lang.reflect)
runReflectiveCall:59, FrameworkMethod$1 (org.junit.runners.model)
run:12, ReflectiveCallable (org.junit.internal.runners.model)
invokeExplosively:56, FrameworkMethod (org.junit.runners.model)
evaluate:17, InvokeMethod (org.junit.internal.runners.statements)
evaluate:74, RunBeforeTestExecutionCallbacks (org.springframework.test.context.junit4.statements)
evaluate:84, RunAfterTestExecutionCallbacks (org.springframework.test.context.junit4.statements)
evaluate:75, RunBeforeTestMethodCallbacks (org.springframework.test.context.junit4.statements)
evaluate:86, RunAfterTestMethodCallbacks (org.springframework.test.context.junit4.statements)
evaluate:84, SpringRepeat (org.springframework.test.context.junit4.statements)
runLeaf:366, ParentRunner (org.junit.runners)
runChild:251, SpringJUnit4ClassRunner (org.springframework.test.context.junit4)
runChild:97, SpringJUnit4ClassRunner (org.springframework.test.context.junit4)
run:331, ParentRunner$4 (org.junit.runners)
schedule:79, ParentRunner$1 (org.junit.runners)
runChildren:329, ParentRunner (org.junit.runners)
access$100:66, ParentRunner (org.junit.runners)
evaluate:293, ParentRunner$2 (org.junit.runners)
evaluate:61, RunBeforeTestClassCallbacks (org.springframework.test.context.junit4.statements)
evaluate:70, RunAfterTestClassCallbacks (org.springframework.test.context.junit4.statements)
evaluate:306, ParentRunner$3 (org.junit.runners)
run:413, ParentRunner (org.junit.runners)
run:190, SpringJUnit4ClassRunner (org.springframework.test.context.junit4)
runChild:128, Suite (org.junit.runners)
runChild:27, Suite (org.junit.runners)
run:331, ParentRunner$4 (org.junit.runners)
schedule:79, ParentRunner$1 (org.junit.runners)
runChildren:329, ParentRunner (org.junit.runners)
access$100:66, ParentRunner (org.junit.runners)
evaluate:293, ParentRunner$2 (org.junit.runners)
evaluate:306, ParentRunner$3 (org.junit.runners)
run:413, ParentRunner (org.junit.runners)
run:137, JUnitCore (org.junit.runner)
startRunnerWithArgs:69, JUnit4IdeaTestRunner (com.intellij.junit4)
execute:38, IdeaTestRunner$Repeater$1 (com.intellij.rt.junit)
repeat:11, TestsRepeater (com.intellij.rt.execution.junit)
startRunnerWithArgs:35, IdeaTestRunner$Repeater (com.intellij.rt.junit)
prepareStreamsAndStart:235, JUnitStarter (com.intellij.rt.junit)
main:54, JUnitStarter (com.intellij.rt.junit)

网络io

send:157, NettyChannel (org.apache.dubbo.remoting.transport.netty4)
send:181, AbstractClient (org.apache.dubbo.remoting.transport)
send:53, AbstractPeer (org.apache.dubbo.remoting.transport)
request:137, HeaderExchangeChannel (org.apache.dubbo.remoting.exchange.support.header)
request:95, HeaderExchangeClient (org.apache.dubbo.remoting.exchange.support.header)
request:93, ReferenceCountExchangeClient (org.apache.dubbo.rpc.protocol.dubbo)
doInvoke:108, DubboInvoker (org.apache.dubbo.rpc.protocol.dubbo)
invoke:173, AbstractInvoker (org.apache.dubbo.rpc.protocol)
invoke:52, AsyncToSyncInvoker (org.apache.dubbo.rpc.protocol)
invoke:78, ListenerInvokerWrapper (org.apache.dubbo.rpc.listener)
invoke:91, MonitorFilter (org.apache.dubbo.monitor.support)
invoke:61, FilterNode (org.apache.dubbo.rpc.protocol)
invoke:52, FutureFilter (org.apache.dubbo.rpc.protocol.dubbo.filter)
invoke:61, FilterNode (org.apache.dubbo.rpc.protocol)
invoke:69, ConsumerContextFilter (org.apache.dubbo.rpc.filter)
invoke:61, FilterNode (org.apache.dubbo.rpc.protocol)
invoke:56, InvokerWrapper (org.apache.dubbo.rpc.protocol)
doInvoke:79, FailoverClusterInvoker (org.apache.dubbo.rpc.cluster.support)
invoke:265, AbstractClusterInvoker (org.apache.dubbo.rpc.cluster.support)
intercept:47, ClusterInterceptor (org.apache.dubbo.rpc.cluster.interceptor)
invoke:92, AbstractCluster$InterceptorInvokerNode (org.apache.dubbo.rpc.cluster.support.wrapper)
invoke:93, MockClusterInvoker (org.apache.dubbo.rpc.cluster.support.wrapper)
invoke:170, MigrationInvoker (org.apache.dubbo.registry.client.migration)
invoke:96, InvokerInvocationHandler (org.apache.dubbo.rpc.proxy)
testRpc:-1, proxy1 (org.apache.dubbo.common.bytecode)
testRpc:30, ThirdDubboManagerImpl (com.patpat.mms.mdp.biz.engine.dependencies.api.impl)
testRpc:41, PushTest (com.patpat.mms.mdp.biz.engine.rest)
invoke0:-1, NativeMethodAccessorImpl (jdk.internal.reflect)
invoke:62, NativeMethodAccessorImpl (jdk.internal.reflect)
invoke:43, DelegatingMethodAccessorImpl (jdk.internal.reflect)
invoke:566, Method (java.lang.reflect)
runReflectiveCall:59, FrameworkMethod$1 (org.junit.runners.model)
run:12, ReflectiveCallable (org.junit.internal.runners.model)
invokeExplosively:56, FrameworkMethod (org.junit.runners.model)
evaluate:17, InvokeMethod (org.junit.internal.runners.statements)
evaluate:74, RunBeforeTestExecutionCallbacks (org.springframework.test.context.junit4.statements)
evaluate:84, RunAfterTestExecutionCallbacks (org.springframework.test.context.junit4.statements)
evaluate:75, RunBeforeTestMethodCallbacks (org.springframework.test.context.junit4.statements)
evaluate:86, RunAfterTestMethodCallbacks (org.springframework.test.context.junit4.statements)
evaluate:84, SpringRepeat (org.springframework.test.context.junit4.statements)
runLeaf:366, ParentRunner (org.junit.runners)
runChild:251, SpringJUnit4ClassRunner (org.springframework.test.context.junit4)
runChild:97, SpringJUnit4ClassRunner (org.springframework.test.context.junit4)
run:331, ParentRunner$4 (org.junit.runners)
schedule:79, ParentRunner$1 (org.junit.runners)
runChildren:329, ParentRunner (org.junit.runners)
access$100:66, ParentRunner (org.junit.runners)
evaluate:293, ParentRunner$2 (org.junit.runners)
evaluate:61, RunBeforeTestClassCallbacks (org.springframework.test.context.junit4.statements)
evaluate:70, RunAfterTestClassCallbacks (org.springframework.test.context.junit4.statements)
evaluate:306, ParentRunner$3 (org.junit.runners)
run:413, ParentRunner (org.junit.runners)
run:190, SpringJUnit4ClassRunner (org.springframework.test.context.junit4)
run:137, JUnitCore (org.junit.runner)
startRunnerWithArgs:69, JUnit4IdeaTestRunner (com.intellij.junit4)
execute:38, IdeaTestRunner$Repeater$1 (com.intellij.rt.junit)
repeat:11, TestsRepeater (com.intellij.rt.execution.junit)
startRunnerWithArgs:35, IdeaTestRunner$Repeater (com.intellij.rt.junit)
prepareStreamsAndStart:235, JUnitStarter (com.intellij.rt.junit)
main:54, JUnitStarter (com.intellij.rt.junit)
            final WriteTask task = WriteTask.newInstance(next, m, promise, flush);

堆栈

run:1067, AbstractChannelHandlerContext$WriteTask (io.netty.channel)
safeExecute$$$capture:164, AbstractEventExecutor (io.netty.util.concurrent)
safeExecute:-1, AbstractEventExecutor (io.netty.util.concurrent)
- Async stack trace
addTask:-1, SingleThreadEventExecutor (io.netty.util.concurrent)
execute:828, SingleThreadEventExecutor (io.netty.util.concurrent)
execute:818, SingleThreadEventExecutor (io.netty.util.concurrent)
safeExecute:989, AbstractChannelHandlerContext (io.netty.channel)
write:796, AbstractChannelHandlerContext (io.netty.channel)
writeAndFlush:758, AbstractChannelHandlerContext (io.netty.channel)
writeAndFlush:808, AbstractChannelHandlerContext (io.netty.channel)
writeAndFlush:1025, DefaultChannelPipeline (io.netty.channel)
writeAndFlush:306, AbstractChannel (io.netty.channel)
send:162, NettyChannel (org.apache.dubbo.remoting.transport.netty4)
send:181, AbstractClient (org.apache.dubbo.remoting.transport)
send:53, AbstractPeer (org.apache.dubbo.remoting.transport)
request:137, HeaderExchangeChannel (org.apache.dubbo.remoting.exchange.support.header)
request:95, HeaderExchangeClient (org.apache.dubbo.remoting.exchange.support.header)
request:93, ReferenceCountExchangeClient (org.apache.dubbo.rpc.protocol.dubbo)
doInvoke:108, DubboInvoker (org.apache.dubbo.rpc.protocol.dubbo)
invoke:173, AbstractInvoker (org.apache.dubbo.rpc.protocol)
invoke:52, AsyncToSyncInvoker (org.apache.dubbo.rpc.protocol)
invoke:78, ListenerInvokerWrapper (org.apache.dubbo.rpc.listener)
invoke:91, MonitorFilter (org.apache.dubbo.monitor.support)
invoke:61, FilterNode (org.apache.dubbo.rpc.protocol)
invoke:52, FutureFilter (org.apache.dubbo.rpc.protocol.dubbo.filter)
invoke:61, FilterNode (org.apache.dubbo.rpc.protocol)
invoke:69, ConsumerContextFilter (org.apache.dubbo.rpc.filter)
invoke:61, FilterNode (org.apache.dubbo.rpc.protocol)
invoke:56, InvokerWrapper (org.apache.dubbo.rpc.protocol)
doInvoke:79, FailoverClusterInvoker (org.apache.dubbo.rpc.cluster.support)
invoke:265, AbstractClusterInvoker (org.apache.dubbo.rpc.cluster.support)
intercept:47, ClusterInterceptor (org.apache.dubbo.rpc.cluster.interceptor)
invoke:92, AbstractCluster$InterceptorInvokerNode (org.apache.dubbo.rpc.cluster.support.wrapper)
invoke:93, MockClusterInvoker (org.apache.dubbo.rpc.cluster.support.wrapper)
invoke:170, MigrationInvoker (org.apache.dubbo.registry.client.migration)
invoke:96, InvokerInvocationHandler (org.apache.dubbo.rpc.proxy)
testRpc:-1, proxy1 (org.apache.dubbo.common.bytecode)
testRpc:30, ThirdDubboManagerImpl (com.patpat.mms.mdp.biz.engine.dependencies.api.impl)
testRpc:41, PushTest (com.patpat.mms.mdp.biz.engine.rest)
invoke0:-2, NativeMethodAccessorImpl (jdk.internal.reflect)
invoke:62, NativeMethodAccessorImpl (jdk.internal.reflect)
invoke:43, DelegatingMethodAccessorImpl (jdk.internal.reflect)
invoke:566, Method (java.lang.reflect)
runReflectiveCall:59, FrameworkMethod$1 (org.junit.runners.model)
run:12, ReflectiveCallable (org.junit.internal.runners.model)
invokeExplosively:56, FrameworkMethod (org.junit.runners.model)
evaluate:17, InvokeMethod (org.junit.internal.runners.statements)
evaluate:74, RunBeforeTestExecutionCallbacks (org.springframework.test.context.junit4.statements)
evaluate:84, RunAfterTestExecutionCallbacks (org.springframework.test.context.junit4.statements)
evaluate:75, RunBeforeTestMethodCallbacks (org.springframework.test.context.junit4.statements)
evaluate:86, RunAfterTestMethodCallbacks (org.springframework.test.context.junit4.statements)
evaluate:84, SpringRepeat (org.springframework.test.context.junit4.statements)
runLeaf:366, ParentRunner (org.junit.runners)
runChild:251, SpringJUnit4ClassRunner (org.springframework.test.context.junit4)
runChild:97, SpringJUnit4ClassRunner (org.springframework.test.context.junit4)
run:331, ParentRunner$4 (org.junit.runners)
schedule:79, ParentRunner$1 (org.junit.runners)
runChildren:329, ParentRunner (org.junit.runners)
access$100:66, ParentRunner (org.junit.runners)
evaluate:293, ParentRunner$2 (org.junit.runners)
evaluate:61, RunBeforeTestClassCallbacks (org.springframework.test.context.junit4.statements)
evaluate:70, RunAfterTestClassCallbacks (org.springframework.test.context.junit4.statements)
evaluate:306, ParentRunner$3 (org.junit.runners)
run:413, ParentRunner (org.junit.runners)
run:190, SpringJUnit4ClassRunner (org.springframework.test.context.junit4)
run:137, JUnitCore (org.junit.runner)
startRunnerWithArgs:69, JUnit4IdeaTestRunner (com.intellij.junit4)
execute:38, IdeaTestRunner$Repeater$1 (com.intellij.rt.junit)
repeat:11, TestsRepeater (com.intellij.rt.execution.junit)
startRunnerWithArgs:35, IdeaTestRunner$Repeater (com.intellij.rt.junit)
prepareStreamsAndStart:235, JUnitStarter (com.intellij.rt.junit)
main:54, JUnitStarter (com.intellij.rt.junit)

相关阅读

jdk 编译

· 3 min read

前言

jdk 某个版本之后是自举的,所以编译jdk之前先有一个jdk。 主要参照https://openjdk.java.net/groups/build/doc/building.html

下载jdk
字节码

src\hotspot\share\interpreter\bytecodes.cpp

BytecodeInterpreter::run

(gdb) bt
#0 TemplateTable::if_icmp (cc=4294967295) at /home/ubuntu/jdk/src/hotspot/cpu/x86/templateTable_x86.cpp:2381
#1 0x00007ffff70a9519 in Template::generate (this=0x7ffff7d60be0 <TemplateTable::_template_table+5088>, masm=0x7ffff0019760) at /home/ubuntu/jdk/src/hotspot/share/interpreter/templateTable.cpp:63
#2 0x00007ffff709bde8 in TemplateInterpreterGenerator::generate_and_dispatch (this=0x7ffff5c5da40, t=0x7ffff7d60be0 <TemplateTable::_template_table+5088>, tos_out=vtos)
at /home/ubuntu/jdk/src/hotspot/share/interpreter/templateInterpreterGenerator.cpp:392
#3 0x00007ffff709b934 in TemplateInterpreterGenerator::set_short_entry_points (this=0x7ffff5c5da40, t=0x7ffff7d60be0 <TemplateTable::_template_table+5088>,
bep=@0x7ffff5c5d398: 0x7fffe1008a37 "H\211d$\330H\201", <incomplete sequence \354\200>, cep=@0x7ffff5c5d3a0: 0x7fffe1008a37 "H\211d$\330H\201", <incomplete sequence \354\200>,
sep=@0x7ffff5c5d3a8: 0x7fffe1008a37 "H\211d$\330H\201", <incomplete sequence \354\200>, aep=@0x7ffff5c5d3b0: 0x7fffe1008a37 "H\211d$\330H\201", <incomplete sequence \354\200>,
iep=@0x7ffff5c5d3b8: 0x7fffe1028807 "PSQRH\213M\330H\205\311\017\204", <incomplete sequence \312>, lep=@0x7ffff5c5d3c0: 0x7fffe1008a37 "H\211d$\330H\201", <incomplete sequence \354\200>,
fep=@0x7ffff5c5d3c8: 0x7fffe1008a37 "H\211d$\330H\201", <incomplete sequence \354\200>, dep=@0x7ffff5c5d3d0: 0x7fffe1008a37 "H\211d$\330H\201", <incomplete sequence \354\200>,
vep=@0x7ffff5c5d3d8: 0x7fffe1028800 "\213\004$H\203\304\bPSQRH\213M\330H\205\311\017\204", <incomplete sequence \312>) at /home/ubuntu/jdk/src/hotspot/share/interpreter/templateInterpreterGenerator.cpp:356
#4 0x00007ffff709b46c in TemplateInterpreterGenerator::set_entry_points (this=0x7ffff5c5da40, code=Bytecodes::_if_icmpeq) at /home/ubuntu/jdk/src/hotspot/share/interpreter/templateInterpreterGenerator.cpp:325
#5 0x00007ffff709b06d in TemplateInterpreterGenerator::set_entry_points_for_all_bytes (this=0x7ffff5c5da40) at /home/ubuntu/jdk/src/hotspot/share/interpreter/templateInterpreterGenerator.cpp:281
#6 0x00007ffff709ac13 in TemplateInterpreterGenerator::generate_all (this=0x7ffff5c5da40) at /home/ubuntu/jdk/src/hotspot/share/interpreter/templateInterpreterGenerator.cpp:234
#7 0x00007ffff70993cb in TemplateInterpreterGenerator::TemplateInterpreterGenerator (this=0x7ffff5c5da40, _code=0x7ffff00a28b0) at /home/ubuntu/jdk/src/hotspot/share/interpreter/templateInterpreterGenerator.cpp:42
#8 0x00007ffff7097e5b in TemplateInterpreter::initialize () at /home/ubuntu/jdk/src/hotspot/share/interpreter/templateInterpreter.cpp:56
#9 0x00007ffff69e06a2 in interpreter_init () at /home/ubuntu/jdk/src/hotspot/share/interpreter/interpreter.cpp:116
#10 0x00007ffff69bbe73 in init_globals () at /home/ubuntu/jdk/src/hotspot/share/runtime/init.cpp:119
#11 0x00007ffff70d59b7 in Threads::create_vm (args=0x7ffff5c5de20, canTryAgain=0x7ffff5c5dd2b) at /home/ubuntu/jdk/src/hotspot/share/runtime/thread.cpp:3728
#12 0x00007ffff6adcd5d in JNI_CreateJavaVM_inner (vm=0x7ffff5c5de78, penv=0x7ffff5c5de80, args=0x7ffff5c5de20) at /home/ubuntu/jdk/src/hotspot/share/prims/jni.cpp:3945
#13 0x00007ffff6add0b1 in JNI_CreateJavaVM (vm=0x7ffff5c5de78, penv=0x7ffff5c5de80, args=0x7ffff5c5de20) at /home/ubuntu/jdk/src/hotspot/share/prims/jni.cpp:4036
#14 0x00007ffff7fba88c in InitializeJVM (pvm=0x7ffff5c5de78, penv=0x7ffff5c5de80, ifn=0x7ffff5c5ded0) at /home/ubuntu/jdk/src/java.base/share/native/libjli/java.c:1527
#15 0x00007ffff7fb7447 in JavaMain (_args=0x7fffffffb040) at /home/ubuntu/jdk/src/java.base/share/native/libjli/java.c:414
#16 0x00007ffff7d7a609 in start_thread (arg=<optimized out>) at pthread_create.c:477
#17 0x00007ffff7ed8293 in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:95

类加载

Thread 2 "java" hit Breakpoint 3, SystemDictionary::load_instance_class (class_name=0x7fffcc2d90f0, class_loader=..., __the_thread__=0x7ffff001b800)
at /home/dinosaur/jdk12/jdk-jdk-12-25/src/hotspot/share/classfile/systemDictionary.cpp:1386
1386 InstanceKlass* SystemDictionary::load_instance_class(Symbol* class_name, Handle class_loader, TRAPS) {
(gdb) bt
#0 SystemDictionary::load_instance_class (class_name=0x7fffcc2d90f0, class_loader=..., __the_thread__=0x7ffff001b800)
at /home/dinosaur/jdk12/jdk-jdk-12-25/src/hotspot/share/classfile/systemDictionary.cpp:1386
#1 0x00007ffff61bf8ab in SystemDictionary::resolve_instance_class_or_null (name=0x7fffcc2d90f0, class_loader=..., protection_domain=..., __the_thread__=0x7ffff001b800)
at /home/dinosaur/jdk12/jdk-jdk-12-25/src/hotspot/share/classfile/systemDictionary.cpp:854
#2 0x00007ffff61bdcf8 in SystemDictionary::resolve_instance_class_or_null_helper (class_name=0x7fffcc2d90f0, class_loader=..., protection_domain=..., __the_thread__=0x7ffff001b800)
at /home/dinosaur/jdk12/jdk-jdk-12-25/src/hotspot/share/classfile/systemDictionary.cpp:272
#3 0x00007ffff61bdb5e in SystemDictionary::resolve_or_null (class_name=0x7fffcc2d90f0, class_loader=..., protection_domain=..., __the_thread__=0x7ffff001b800)
at /home/dinosaur/jdk12/jdk-jdk-12-25/src/hotspot/share/classfile/systemDictionary.cpp:255
#4 0x00007ffff61bd7d1 in SystemDictionary::resolve_or_fail (class_name=0x7fffcc2d90f0, class_loader=..., protection_domain=..., throw_error=true, __the_thread__=0x7ffff001b800)
at /home/dinosaur/jdk12/jdk-jdk-12-25/src/hotspot/share/classfile/systemDictionary.cpp:203
#5 0x00007ffff61bdae8 in SystemDictionary::resolve_or_fail (class_name=0x7fffcc2d90f0, throw_error=true, __the_thread__=0x7ffff001b800)
at /home/dinosaur/jdk12/jdk-jdk-12-25/src/hotspot/share/classfile/systemDictionary.cpp:245
#6 0x00007ffff61c3490 in SystemDictionary::resolve_wk_klass (id=SystemDictionary::Object_klass_knum, __the_thread__=0x7ffff001b800)
at /home/dinosaur/jdk12/jdk-jdk-12-25/src/hotspot/share/classfile/systemDictionary.cpp:1938
#7 0x00007ffff61c35c5 in SystemDictionary::resolve_wk_klasses_until (limit_id=SystemDictionary::Cloneable_klass_knum, start_id=@0x7ffff7fbc974: SystemDictionary::Object_klass_knum,
__the_thread__=0x7ffff001b800) at /home/dinosaur/jdk12/jdk-jdk-12-25/src/hotspot/share/classfile/systemDictionary.cpp:1948
#8 0x00007ffff5c5c46d in SystemDictionary::resolve_wk_klasses_through (end_id=SystemDictionary::Class_klass_knum, start_id=@0x7ffff7fbc974: SystemDictionary::Object_klass_knum,
__the_thread__=0x7ffff001b800) at /home/dinosaur/jdk12/jdk-jdk-12-25/src/hotspot/share/classfile/systemDictionary.hpp:391
#9 0x00007ffff61c37a3 in SystemDictionary::resolve_well_known_classes (__the_thread__=0x7ffff001b800) at /home/dinosaur/jdk12/jdk-jdk-12-25/src/hotspot/share/classfile/systemDictionary.cpp:1991
#10 0x00007ffff61c32d8 in SystemDictionary::initialize (__the_thread__=0x7ffff001b800) at /home/dinosaur/jdk12/jdk-jdk-12-25/src/hotspot/share/classfile/systemDictionary.cpp:1898
#11 0x00007ffff623b65c in Universe::genesis (__the_thread__=0x7ffff001b800) at /home/dinosaur/jdk12/jdk-jdk-12-25/src/hotspot/share/memory/universe.cpp:329
#12 0x00007ffff623dd21 in universe2_init () at /home/dinosaur/jdk12/jdk-jdk-12-25/src/hotspot/share/memory/universe.cpp:953
#13 0x00007ffff5a575e7 in init_globals () at /home/dinosaur/jdk12/jdk-jdk-12-25/src/hotspot/share/runtime/init.cpp:125
#14 0x00007ffff620ecbe in Threads::create_vm (args=0x7ffff7fbce20, canTryAgain=0x7ffff7fbcd2b) at /home/dinosaur/jdk12/jdk-jdk-12-25/src/hotspot/share/runtime/thread.cpp:3731
#15 0x00007ffff5b6b598 in JNI_CreateJavaVM_inner (vm=0x7ffff7fbce78, penv=0x7ffff7fbce80, args=0x7ffff7fbce20) at /home/dinosaur/jdk12/jdk-jdk-12-25/src/hotspot/share/prims/jni.cpp:3935
#16 0x00007ffff5b6b8c2 in JNI_CreateJavaVM (vm=0x7ffff7fbce78, penv=0x7ffff7fbce80, args=0x7ffff7fbce20) at /home/dinosaur/jdk12/jdk-jdk-12-25/src/hotspot/share/prims/jni.cpp:4021
#17 0x00007ffff7bc6601 in InitializeJVM (pvm=0x7ffff7fbce78, penv=0x7ffff7fbce80, ifn=0x7ffff7fbced0) at /home/dinosaur/jdk12/jdk-jdk-12-25/src/java.base/share/native/libjli/java.c:1529
#18 0x00007ffff7bc320c in JavaMain (_args=0x7fffffffaa30) at /home/dinosaur/jdk12/jdk-jdk-12-25/src/java.base/share/native/libjli/java.c:414
#19 0x00007ffff71956db in start_thread (arg=0x7ffff7fbd700) at pthread_create.c:463
#20 0x00007ffff78ef61f in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:95


(gdb) p class_name->_body@10
$14 = {"ja", "va", "/l", "an", "g/", "Ob", "je", "ct", "\361", <incomplete sequence \361>, "\377\377"}

解析文件流

ClassFileParser::parse_stream

find_transitive_override

重载

find_transitive_override
update_inherited_vtable

签名

Method::name_and_sig_as_C_string

相关阅读

java-wait-notify

· 9 min read

背景

java的线程间通信,偶尔会用到wait和notify

实现

注册:

// Register native methods of Object
void java_lang_Object::register_natives(TRAPS) {
InstanceKlass* obj = vmClasses::Object_klass();
Method::register_native(obj, vmSymbols::hashCode_name(),
vmSymbols::void_int_signature(), (address) &JVM_IHashCode, CHECK);
Method::register_native(obj, vmSymbols::wait_name(),
vmSymbols::long_void_signature(), (address) &JVM_MonitorWait, CHECK);
Method::register_native(obj, vmSymbols::notify_name(),
vmSymbols::void_method_signature(), (address) &JVM_MonitorNotify, CHECK);
Method::register_native(obj, vmSymbols::notifyAll_name(),
vmSymbols::void_method_signature(), (address) &JVM_MonitorNotifyAll, CHECK);
Method::register_native(obj, vmSymbols::clone_name(),
vmSymbols::void_object_signature(), (address) &JVM_Clone, THREAD);
}
// -----------------------------------------------------------------------------
// Wait/Notify/NotifyAll
//
// Note: a subset of changes to ObjectMonitor::wait()
// will need to be replicated in complete_exit
void ObjectMonitor::wait(jlong millis, bool interruptible, TRAPS) {
JavaThread* current = THREAD;

assert(InitDone, "Unexpectedly not initialized");

CHECK_OWNER(); // Throws IMSE if not owner.

EventJavaMonitorWait event;

// check for a pending interrupt
if (interruptible && current->is_interrupted(true) && !HAS_PENDING_EXCEPTION) {
// post monitor waited event. Note that this is past-tense, we are done waiting.
if (JvmtiExport::should_post_monitor_waited()) {
// Note: 'false' parameter is passed here because the
// wait was not timed out due to thread interrupt.
JvmtiExport::post_monitor_waited(current, this, false);

// In this short circuit of the monitor wait protocol, the
// current thread never drops ownership of the monitor and
// never gets added to the wait queue so the current thread
// cannot be made the successor. This means that the
// JVMTI_EVENT_MONITOR_WAITED event handler cannot accidentally
// consume an unpark() meant for the ParkEvent associated with
// this ObjectMonitor.
}
if (event.should_commit()) {
post_monitor_wait_event(&event, this, 0, millis, false);
}
THROW(vmSymbols::java_lang_InterruptedException());
return;
}

assert(current->_Stalled == 0, "invariant");
current->_Stalled = intptr_t(this);
current->set_current_waiting_monitor(this);

// create a node to be put into the queue
// Critically, after we reset() the event but prior to park(), we must check
// for a pending interrupt.
ObjectWaiter node(current);
node.TState = ObjectWaiter::TS_WAIT;
current->_ParkEvent->reset();
OrderAccess::fence(); // ST into Event; membar ; LD interrupted-flag

// Enter the waiting queue, which is a circular doubly linked list in this case
// but it could be a priority queue or any data structure.
// _WaitSetLock protects the wait queue. Normally the wait queue is accessed only
// by the the owner of the monitor *except* in the case where park()
// returns because of a timeout of interrupt. Contention is exceptionally rare
// so we use a simple spin-lock instead of a heavier-weight blocking lock.

Thread::SpinAcquire(&_WaitSetLock, "WaitSet - add");
AddWaiter(&node);
Thread::SpinRelease(&_WaitSetLock);

_Responsible = NULL;

intx save = _recursions; // record the old recursion count
_waiters++; // increment the number of waiters
_recursions = 0; // set the recursion level to be 1
exit(current); // exit the monitor
guarantee(owner_raw() != current, "invariant");

// The thread is on the WaitSet list - now park() it.
// On MP systems it's conceivable that a brief spin before we park
// could be profitable.
//
// TODO-FIXME: change the following logic to a loop of the form
// while (!timeout && !interrupted && _notified == 0) park()

int ret = OS_OK;
int WasNotified = 0;

// Need to check interrupt state whilst still _thread_in_vm
bool interrupted = interruptible && current->is_interrupted(false);

{ // State transition wrappers
OSThread* osthread = current->osthread();
OSThreadWaitState osts(osthread, true);

assert(current->thread_state() == _thread_in_vm, "invariant");

{
ClearSuccOnSuspend csos(this);
ThreadBlockInVMPreprocess<ClearSuccOnSuspend> tbivs(current, csos, true /* allow_suspend */);
if (interrupted || HAS_PENDING_EXCEPTION) {
// Intentionally empty
} else if (node._notified == 0) {
if (millis <= 0) {
current->_ParkEvent->park();
} else {
ret = current->_ParkEvent->park(millis);
}
}
}

// Node may be on the WaitSet, the EntryList (or cxq), or in transition
// from the WaitSet to the EntryList.
// See if we need to remove Node from the WaitSet.
// We use double-checked locking to avoid grabbing _WaitSetLock
// if the thread is not on the wait queue.
//
// Note that we don't need a fence before the fetch of TState.
// In the worst case we'll fetch a old-stale value of TS_WAIT previously
// written by the is thread. (perhaps the fetch might even be satisfied
// by a look-aside into the processor's own store buffer, although given
// the length of the code path between the prior ST and this load that's
// highly unlikely). If the following LD fetches a stale TS_WAIT value
// then we'll acquire the lock and then re-fetch a fresh TState value.
// That is, we fail toward safety.

if (node.TState == ObjectWaiter::TS_WAIT) {
Thread::SpinAcquire(&_WaitSetLock, "WaitSet - unlink");
if (node.TState == ObjectWaiter::TS_WAIT) {
DequeueSpecificWaiter(&node); // unlink from WaitSet
assert(node._notified == 0, "invariant");
node.TState = ObjectWaiter::TS_RUN;
}
Thread::SpinRelease(&_WaitSetLock);
}

// The thread is now either on off-list (TS_RUN),
// on the EntryList (TS_ENTER), or on the cxq (TS_CXQ).
// The Node's TState variable is stable from the perspective of this thread.
// No other threads will asynchronously modify TState.
guarantee(node.TState != ObjectWaiter::TS_WAIT, "invariant");
OrderAccess::loadload();
if (_succ == current) _succ = NULL;
WasNotified = node._notified;

// Reentry phase -- reacquire the monitor.
// re-enter contended monitor after object.wait().
// retain OBJECT_WAIT state until re-enter successfully completes
// Thread state is thread_in_vm and oop access is again safe,
// although the raw address of the object may have changed.
// (Don't cache naked oops over safepoints, of course).

// post monitor waited event. Note that this is past-tense, we are done waiting.
if (JvmtiExport::should_post_monitor_waited()) {
JvmtiExport::post_monitor_waited(current, this, ret == OS_TIMEOUT);

if (node._notified != 0 && _succ == current) {
// In this part of the monitor wait-notify-reenter protocol it
// is possible (and normal) for another thread to do a fastpath
// monitor enter-exit while this thread is still trying to get
// to the reenter portion of the protocol.
//
// The ObjectMonitor was notified and the current thread is
// the successor which also means that an unpark() has already
// been done. The JVMTI_EVENT_MONITOR_WAITED event handler can
// consume the unpark() that was done when the successor was
// set because the same ParkEvent is shared between Java
// monitors and JVM/TI RawMonitors (for now).
//
// We redo the unpark() to ensure forward progress, i.e., we
// don't want all pending threads hanging (parked) with none
// entering the unlocked monitor.
node._event->unpark();
}
}

if (event.should_commit()) {
post_monitor_wait_event(&event, this, node._notifier_tid, millis, ret == OS_TIMEOUT);
}

OrderAccess::fence();

assert(current->_Stalled != 0, "invariant");
current->_Stalled = 0;

assert(owner_raw() != current, "invariant");
ObjectWaiter::TStates v = node.TState;
if (v == ObjectWaiter::TS_RUN) {
enter(current);
} else {
guarantee(v == ObjectWaiter::TS_ENTER || v == ObjectWaiter::TS_CXQ, "invariant");
ReenterI(current, &node);
node.wait_reenter_end(this);
}

// current has reacquired the lock.
// Lifecycle - the node representing current must not appear on any queues.
// Node is about to go out-of-scope, but even if it were immortal we wouldn't
// want residual elements associated with this thread left on any lists.
guarantee(node.TState == ObjectWaiter::TS_RUN, "invariant");
assert(owner_raw() == current, "invariant");
assert(_succ != current, "invariant");
} // OSThreadWaitState()

current->set_current_waiting_monitor(NULL);

guarantee(_recursions == 0, "invariant");
_recursions = save // restore the old recursion count
+ JvmtiDeferredUpdates::get_and_reset_relock_count_after_wait(current); // increased by the deferred relock count
_waiters--; // decrement the number of waiters

// Verify a few postconditions
assert(owner_raw() == current, "invariant");
assert(_succ != current, "invariant");
assert(object()->mark() == markWord::encode(this), "invariant");

// check if the notification happened
if (!WasNotified) {
// no, it could be timeout or Thread.interrupt() or both
// check for interrupt event, otherwise it is timeout
if (interruptible && current->is_interrupted(true) && !HAS_PENDING_EXCEPTION) {
THROW(vmSymbols::java_lang_InterruptedException());
}
}

// NOTE: Spurious wake up will be consider as timeout.
// Monitor notify has precedence over thread interrupt.
}

wait:

Thread 20 "Thread-0" hit Breakpoint 2, __pthread_cond_wait (cond=0x7ffff0510058, mutex=0x7ffff0510030) at forward.c:121
121 forward.c: No such file or directory.
(gdb) bt
#0 __pthread_cond_wait (cond=0x7ffff0510058, mutex=0x7ffff0510030) at forward.c:121
#1 0x00007ffff6c21713 in os::PlatformEvent::park (this=0x7ffff0510000) at /home/ubuntu/daixiao/jdk/src/hotspot/os/posix/os_posix.cpp:1484
#2 0x00007ffff6bd003c in ObjectMonitor::wait (this=0x7fffac0013b0, millis=0, interruptible=true, __the_thread__=0x7ffff050f5b0) at /home/ubuntu/daixiao/jdk/src/hotspot/share/runtime/objectMonitor.cpp:1544
#3 0x00007ffff6e90188 in ObjectSynchronizer::wait (obj=..., millis=0, __the_thread__=0x7ffff050f5b0) at /home/ubuntu/daixiao/jdk/src/hotspot/share/runtime/synchronizer.cpp:654
#4 0x00007ffff68298ae in JVM_MonitorWait (env=0x7ffff050f8a8, handle=0x7fffd0df77c0, ms=0) at /home/ubuntu/daixiao/jdk/src/hotspot/share/prims/jvm.cpp:617
#5 0x00007fffe100f68b in ?? ()
#6 0x00000008f7c32db8 in ?? ()
#7 0x00007ffff050f5b0 in ?? ()
#8 0x00007fffd0df7760 in ?? ()
#9 0x00007fffd0df7748 in ?? ()
#10 0x0000000000000000 in ?? ()

notify:

(gdb) bt
#0 __pthread_cond_signal (cond=0x7ffff04f0958) at forward.c:110
#1 0x00007ffff6c21c13 in os::PlatformEvent::unpark (this=0x7ffff04f0900) at /home/ubuntu/daixiao/jdk/src/hotspot/os/posix/os_posix.cpp:1590
#2 0x00007ffff6bcf654 in ObjectMonitor::ExitEpilog (this=0x7fffac0010b0, current=0x7ffff04ef410, Wakee=0x0) at /home/ubuntu/daixiao/jdk/src/hotspot/share/runtime/objectMonitor.cpp:1350
#3 0x00007ffff6bcf57b in ObjectMonitor::exit (this=0x7fffac0010b0, current=0x7ffff04ef410, not_suspended=true) at /home/ubuntu/daixiao/jdk/src/hotspot/share/runtime/objectMonitor.cpp:1321
#4 0x00007ffff6bcfe8e in ObjectMonitor::wait (this=0x7fffac0010b0, millis=0, interruptible=true, __the_thread__=0x7ffff04ef410) at /home/ubuntu/daixiao/jdk/src/hotspot/share/runtime/objectMonitor.cpp:1515
#5 0x00007ffff6e90188 in ObjectSynchronizer::wait (obj=..., millis=0, __the_thread__=0x7ffff04ef410) at /home/ubuntu/daixiao/jdk/src/hotspot/share/runtime/synchronizer.cpp:654
#6 0x00007ffff68298ae in JVM_MonitorWait (env=0x7ffff04ef708, handle=0x7fffd0df77c0, ms=0) at /home/ubuntu/daixiao/jdk/src/hotspot/share/prims/jvm.cpp:617
#7 0x00007fffe100f68b in ?? ()
#8 0x00000008f7c32db8 in ?? ()
#9 0x00007ffff04ef410 in ?? ()
#10 0x00007fffd0df7760 in ?? ()
#11 0x00007fffd0df7748 in ?? ()
#12 0x0000000000000000 in ?? ()
void PlatformEvent::park() {       // AKA "down()"
// Transitions for _event:
// -1 => -1 : illegal
// 1 => 0 : pass - return immediately
// 0 => -1 : block; then set _event to 0 before returning

// Invariant: Only the thread associated with the PlatformEvent
// may call park().
assert(_nParked == 0, "invariant");

int v;

// atomically decrement _event
for (;;) {
v = _event;
if (Atomic::cmpxchg(&_event, v, v - 1) == v) break;
}
guarantee(v >= 0, "invariant");

if (v == 0) { // Do this the hard way by blocking ...
int status = pthread_mutex_lock(_mutex);
assert_status(status == 0, status, "mutex_lock");
guarantee(_nParked == 0, "invariant");
++_nParked;
while (_event < 0) {
// OS-level "spurious wakeups" are ignored
status = pthread_cond_wait(_cond, _mutex);
assert_status(status == 0 MACOS_ONLY(|| status == ETIMEDOUT),
status, "cond_wait");
}
--_nParked;

_event = 0;
status = pthread_mutex_unlock(_mutex);
assert_status(status == 0, status, "mutex_unlock");
// Paranoia to ensure our locked and lock-free paths interact
// correctly with each other.
OrderAccess::fence();
}
guarantee(_event >= 0, "invariant");
}

demo

#include <stdio.h>
#include <pthread.h>
#include<unistd.h>

pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
pthread_cond_t cond = PTHREAD_COND_INITIALIZER;
int condition = 0;
int count = 0;
pthread_t thread_id;
int consume( void )
{
while( 1 )
{
pthread_mutex_lock( &mutex );
while( condition == 0 )
pthread_cond_wait( &cond, &mutex );
printf( "Consumed %d\n", count );
condition = 0;
pthread_cond_signal( &cond );
pthread_mutex_unlock( &mutex );
}

return( 0 );
}

void* produce( void * arg )
{
while( 1 )
{
pthread_mutex_lock( &mutex );
while( condition == 1 )
pthread_cond_wait( &cond, &mutex );
printf( "Produced %d\n", count++ );
condition = 1;
pthread_cond_signal( &cond );
pthread_mutex_unlock( &mutex );
}
return( 0 );
}

int main( void )
{
pthread_create( thread_id, NULL, &produce, NULL );
return consume();
}

例子

#include<pthread.h>
#include<stdlib.h>
#include<stdio.h>
#include<string.h>
pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
pthread_cond_t cond = PTHREAD_COND_INITIALIZER;
int num = 0;
int main(){
int error = pthread_mutex_lock( &mutex);
if(error){
perror(strerror(error));
exit(0);
}
while(num <= 0){
error = pthread_cond_wait( &cond, &mutex);
if(error){
perror(strerror(error));
exit(0);
}
}
pthread_mutex_unlock(&mutex);
return 0;

}

相关阅读

java Class_forName

· One min read

在看到jdbc使用的例子里面,看到了Class.forName("xxx")的相关调用

Class.forName("com.mysql.jdbc.Driver")

这有什么用的?
其实可以约等于PHP的class_exist,或者说是golang的空引入 import _ "github.com/go-sql-driver/mysql 就是为了调用一下static 块的代码,初始化一下

相关阅读

ik分词

· One min read

es上面安装ik分词

./bin/elasticsearch-plugin install https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v7.4.0/elasticsearch-analysis-ik-7.4.0.zip

返回

-> Downloading https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v7.4.0/elasticsearch-analysis-ik-7.4.0.zip

分词核心函数

相关阅读

java 异常

· One min read

异常例子

import java.io.*;
public class className
{
public void deposit(double amount) throws RemoteException
{
// Method implementation
throw new RemoteException();
}
//Remainder of class definition
}

异常的实质是什么?

实质就是一个获取堆栈的类,这个类特别的地方在于可以获取堆栈,核心也在于获取堆栈和捕获异常

checked exception

来源

The unchecked exception classes are the run-time exception classes and the error classes.

The checked exception classes are all exception classes other than the unchecked exception classes. That is, the checked exception classes are Throwable and all its subclasses other than RuntimeException and its subclasses and Error and its subclasses.

uncheckded exception就是运行时异常类和error类,其他都是checked exception

java string 相关内容

· 2 min read

版本是java8

基本类型和对象

java的string是什么呢? 很明显是对象

特化的+

15.18.1. String Concatenation Operator + If only one operand expression is of type String, then string conversion (§5.1.11) is performed on the other operand to produce a string at run time. 来源

java的字符串连接符是+,而php的是.

stringbuilder

string常量折叠

由于上面提到的jls8中的String Concatenation Operator +提到相关内容,如果操作符中只有一个string类型的话,类型转换会发生在运行时.没有规定两个都是string的时候怎么处理,所以javac将他折叠了

       /** If tree is a concatenation of string literals, replace it
* by a single literal representing the concatenated string.
*/
protected JCExpression foldStrings(JCExpression tree) {
if (!allowStringFolding)
return tree;
ListBuffer<JCExpression> opStack = new ListBuffer<>();
ListBuffer<JCLiteral> litBuf = new ListBuffer<>();
boolean needsFolding = false;
JCExpression curr = tree;
while (true) {
if (curr.hasTag(JCTree.Tag.PLUS)) {
JCBinary op = (JCBinary)curr;
needsFolding |= foldIfNeeded(op.rhs, litBuf, opStack, false);
curr = op.lhs;
} else {
needsFolding |= foldIfNeeded(curr, litBuf, opStack, true);
break; //last one!
}
}
if (needsFolding) {
List<JCExpression> ops = opStack.toList();
JCExpression res = ops.head;
for (JCExpression op : ops.tail) {
res = F.at(op.getStartPosition()).Binary(optag(TokenKind.PLUS), res, op);
storeEnd(res, getEndPos(op));
}
return res;
} else {
return tree;
}

[foldStrings]https://github.com/openjdk/jdk/blob/6bab0f539fba8fb441697846347597b4a0ade428/src/jdk.compiler/share/classes/com/sun/tools/javac/parser/JavacParser.java#L950

相关阅读

java的package与文件路径与编译

· 3 min read

写了很久的php的原生代码,对php相对路径自动加载这类坑的恐惧已经深入骨髓了.
java和golang也有类似的内容,对于写java没多久的我来说,先记录一下

关于类名和classpath的关系,oracle的文档有相关的描述

Class Path and Package Names

Java classes are organized into packages that are mapped to directories in the file system. But, unlike the file system, whenever you specify a package name, you specify the whole package name and never part of it. For example, the package name for java.awt.Button is always specified as java.awt.

For example, suppose you want the JRE to find a class named Cool.class in the package utility.myapp. If the path to that directory is /java/MyClasses/utility/myapp, then you would set the class path so that it contains /java/MyClasses. To run that application, you could use the following java command:

java -classpath /java/MyClasses utility.myapp.Cool When the application runs, the JVM uses the class path settings to find any other classes defined in the utility.myapp package that are used by the Cool class.

The entire package name is specified in the command. It is not possible, for example, to set the class path so it contains /java/MyClasses/utility and use the command java myapp.Cool. The class would not be found.

You might wonder what defines the package name for a class. The answer is that the package name is part of the class and cannot be modified, except by recompiling the class.

首先说编译: 查看javac 的帮助:

javac --help
Usage: javac <options> <source files>

javac 的参数是: javac+文件路径

举个例子: 现在在com的上一级目录上

下面是HelloWorld.java的代码

package com.helloworld;

public class HelloWorld
{
static public int m = 1;
public int i = 1;

}
# ls 
com
# tree
.
└── com
└── helloworld
└── HelloWorld.java

我要怎么编译com/hellowrld/HelloWorld.java下面的文件呢?

这么编译就可以了:

javac com/helloworld/*.java

然后看一下目录树,在下面多了一个class文件

# tree
.
└── com
└── helloworld
├── HelloWorld.class
└── HelloWorld.java

重新开始,我们看看-d 这个参数有什么用:

# mkdir classes
# tree
.
├── classess
└── com
└── helloworld
└── HelloWorld.java

那么我们编译之后会在设置的-d的目录里面添加相关目录:

# javac -d ./classes/    com/helloworld/*.java
# tree
.
├── classes
│   └── com
│   └── helloworld
│   └── HelloWorld.class
├── classess
└── com
└── helloworld
└── HelloWorld.java

相关阅读

maven打包NoClassDefFoundError

· 2 min read

maven打包NoClassDefFoundError

刚刚在学习怎么使用maven,可以编译通过,但是运行命令java -jar xxx.jar 的时候却报了错误NoClassDefFoundError

踩坑开始

踩坑第一步是去stack overflow 找了一个答案,使用插件maven-shade-plugin,其实这个也是正确的答案

这是正确答案

<project>
...
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.2.1</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
...
</project>

相关链接

我踩坑在哪里呢?

我当时不了解xml节点<pluginManagement>下面的plugins节点

  • 这个是错误的写法
<project>
...
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.2.1</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</pluginManagement>
</build>
...
</project>

最终我的写法

最终写法就是得放在build 节点的下一级,不能放在pluginManagement里面的<plugins>节点里面

<project>
...
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.2.1</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
<pluginManagement>
...
</pluginManagement>
</build>
...
</project>

然后运行mvn package 就能打包所有依赖进去

hello world java

· 8 min read

hello

java hello world

public class HelloWorld {

public static void main(String[] args) {
// Prints "Hello, World" to the terminal window.
System.out.println("Hello, World");
}

}


编译

编译 需要添加g 选项

javac -g HelloWorld.java 

调试

方法一:

使用jdb 调试hello wrold

jdb -classpath . HelloWorld
> stop  in HelloWorld.main                                
Deferring breakpoint HelloWorld.main.
It will be set after the class is loaded.
> run
run HelloWorld
Set uncaught java.lang.Throwable
Set deferred uncaught java.lang.Throwable
>
VM Started: Set deferred breakpoint HelloWorld.main

Breakpoint hit: "thread=main", HelloWorld.main(), line=5 bci=0
5 System.out.println("Hello, World");

main[1]

使用maven 编写helloworld

当遇到maven package后,java -java some.jar 说找不到main的时候可以参考以下答案
https://stackoverflow.com/a/9689877/6229548

加载类

(gdb) bt
#0 open64 () at ../sysdeps/unix/syscall-template.S:84
#1 0x00007ffff695b544 in os::open (path=0x7ffff7fcefd0 "/home/dinosaur/jdk8/build/linux-x86_64-normal-server-slowdebug/jdk/classes/java/lang/Class.class", oflag=0, mode=0)
at /home/dinosaur/jdk8/hotspot/src/os/linux/vm/os_linux.cpp:5188
#2 0x00007ffff63ffdfc in ClassPathDirEntry::open_stream (this=0x7ffff006f178, name=0x7ffff000cce8 "java/lang/Class.class", __the_thread__=0x7ffff000c000)
at /home/dinosaur/jdk8/hotspot/src/share/vm/classfile/classLoader.cpp:210
#3 0x00007ffff640055b in LazyClassPathEntry::open_stream (this=0x7ffff001ad48, name=0x7ffff000cce8 "java/lang/Class.class", __the_thread__=0x7ffff000c000)
at /home/dinosaur/jdk8/hotspot/src/share/vm/classfile/classLoader.cpp:330
#4 0x00007ffff640209b in ClassLoader::load_classfile (h_name=0x7ffff4062108, __the_thread__=0x7ffff000c000) at /home/dinosaur/jdk8/hotspot/src/share/vm/classfile/classLoader.cpp:909
#5 0x00007ffff6a8570a in SystemDictionary::load_instance_class (class_name=0x7ffff4062108, class_loader=..., __the_thread__=0x7ffff000c000)
at /home/dinosaur/jdk8/hotspot/src/share/vm/classfile/systemDictionary.cpp:1304
#6 0x00007ffff6a838b8 in SystemDictionary::resolve_instance_class_or_null (name=0x7ffff4062108, class_loader=..., protection_domain=..., __the_thread__=0x7ffff000c000)
at /home/dinosaur/jdk8/hotspot/src/share/vm/classfile/systemDictionary.cpp:779
#7 0x00007ffff6a81ff7 in SystemDictionary::resolve_or_null (class_name=0x7ffff4062108, class_loader=..., protection_domain=..., __the_thread__=0x7ffff000c000)
at /home/dinosaur/jdk8/hotspot/src/share/vm/classfile/systemDictionary.cpp:232
#8 0x00007ffff6a819f2 in SystemDictionary::resolve_or_fail (class_name=0x7ffff4062108, class_loader=..., protection_domain=..., throw_error=true, __the_thread__=0x7ffff000c000)
at /home/dinosaur/jdk8/hotspot/src/share/vm/classfile/systemDictionary.cpp:171
#9 0x00007ffff6a81d64 in SystemDictionary::resolve_or_fail (class_name=0x7ffff4062108, throw_error=true, __the_thread__=0x7ffff000c000)
at /home/dinosaur/jdk8/hotspot/src/share/vm/classfile/systemDictionary.cpp:212
#10 0x00007ffff6a87277 in SystemDictionary::initialize_wk_klass (id=SystemDictionary::Class_klass_knum, init_opt=0, __the_thread__=0x7ffff000c000)
at /home/dinosaur/jdk8/hotspot/src/share/vm/classfile/systemDictionary.cpp:1866
#11 0x00007ffff6a873a7 in SystemDictionary::initialize_wk_klasses_until (limit_id=SystemDictionary::Cloneable_klass_knum, start_id=@0x7ffff7fd0a84: SystemDictionary::Object_klass_knum,
__the_thread__=0x7ffff000c000) at /home/dinosaur/jdk8/hotspot/src/share/vm/classfile/systemDictionary.cpp:1882
#12 0x00007ffff6a8b13c in SystemDictionary::initialize_wk_klasses_through (end_id=SystemDictionary::Class_klass_knum, start_id=@0x7ffff7fd0a84: SystemDictionary::Object_klass_knum,
__the_thread__=0x7ffff000c000) at /home/dinosaur/jdk8/hotspot/src/share/vm/classfile/systemDictionary.hpp:408
#13 0x00007ffff6a874e0 in SystemDictionary::initialize_preloaded_classes (__the_thread__=0x7ffff000c000) at /home/dinosaur/jdk8/hotspot/src/share/vm/classfile/systemDictionary.cpp:1901
#14 0x00007ffff6a87199 in SystemDictionary::initialize (__the_thread__=0x7ffff000c000) at /home/dinosaur/jdk8/hotspot/src/share/vm/classfile/systemDictionary.cpp:1843
#15 0x00007ffff6ad68c9 in Universe::genesis (__the_thread__=0x7ffff000c000) at /home/dinosaur/jdk8/hotspot/src/share/vm/memory/universe.cpp:288
#16 0x00007ffff6ad8db6 in universe2_init () at /home/dinosaur/jdk8/hotspot/src/share/vm/memory/universe.cpp:991
#17 0x00007ffff66463b3 in init_globals () at /home/dinosaur/jdk8/hotspot/src/share/vm/runtime/init.cpp:114
#18 0x00007ffff6ab93ef in Threads::create_vm (args=0x7ffff7fd0e80, canTryAgain=0x7ffff7fd0e03) at /home/dinosaur/jdk8/hotspot/src/share/vm/runtime/thread.cpp:3424
#19 0x00007ffff6702ed0 in JNI_CreateJavaVM (vm=0x7ffff7fd0ed8, penv=0x7ffff7fd0ee0, args=0x7ffff7fd0e80) at /home/dinosaur/jdk8/hotspot/src/share/vm/prims/jni.cpp:5166
#20 0x00007ffff7bc3bda in InitializeJVM (pvm=0x7ffff7fd0ed8, penv=0x7ffff7fd0ee0, ifn=0x7ffff7fd0f30) at /home/dinosaur/jdk8/jdk/src/share/bin/java.c:1145
#21 0x00007ffff7bc1a36 in JavaMain (_args=0x7fffffffa910) at /home/dinosaur/jdk8/jdk/src/share/bin/java.c:371
#22 0x00007ffff73d66ba in start_thread (arg=0x7ffff7fd1700) at pthread_create.c:333
#23 0x00007ffff78f741d in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:109

加载classloader

(gdb) bt
#0 open64 () at ../sysdeps/unix/syscall-template.S:84
#1 0x00007ffff695b544 in os::open (path=0x7ffff7fcefd0 "/home/dinosaur/jdk8/build/linux-x86_64-normal-server-slowdebug/jdk/classes/java/lang/ClassLoader.class", oflag=0, mode=0)
at /home/dinosaur/jdk8/hotspot/src/os/linux/vm/os_linux.cpp:5188
#2 0x00007ffff63ffdfc in ClassPathDirEntry::open_stream (this=0x7ffff006f178, name=0x7ffff000cd08 "java/lang/ClassLoader.class", __the_thread__=0x7ffff000c000)
at /home/dinosaur/jdk8/hotspot/src/share/vm/classfile/classLoader.cpp:210
#3 0x00007ffff640055b in LazyClassPathEntry::open_stream (this=0x7ffff001ad48, name=0x7ffff000cd08 "java/lang/ClassLoader.class", __the_thread__=0x7ffff000c000)
at /home/dinosaur/jdk8/hotspot/src/share/vm/classfile/classLoader.cpp:330
#4 0x00007ffff640209b in ClassLoader::load_classfile (h_name=0x7ffff40621c8, __the_thread__=0x7ffff000c000) at /home/dinosaur/jdk8/hotspot/src/share/vm/classfile/classLoader.cpp:909
#5 0x00007ffff6a8570a in SystemDictionary::load_instance_class (class_name=0x7ffff40621c8, class_loader=..., __the_thread__=0x7ffff000c000)
at /home/dinosaur/jdk8/hotspot/src/share/vm/classfile/systemDictionary.cpp:1304
#6 0x00007ffff6a838b8 in SystemDictionary::resolve_instance_class_or_null (name=0x7ffff40621c8, class_loader=..., protection_domain=..., __the_thread__=0x7ffff000c000)
at /home/dinosaur/jdk8/hotspot/src/share/vm/classfile/systemDictionary.cpp:779
#7 0x00007ffff6a81ff7 in SystemDictionary::resolve_or_null (class_name=0x7ffff40621c8, class_loader=..., protection_domain=..., __the_thread__=0x7ffff000c000)
at /home/dinosaur/jdk8/hotspot/src/share/vm/classfile/systemDictionary.cpp:232
#8 0x00007ffff6a819f2 in SystemDictionary::resolve_or_fail (class_name=0x7ffff40621c8, class_loader=..., protection_domain=..., throw_error=true, __the_thread__=0x7ffff000c000)
at /home/dinosaur/jdk8/hotspot/src/share/vm/classfile/systemDictionary.cpp:171
#9 0x00007ffff6a81d64 in SystemDictionary::resolve_or_fail (class_name=0x7ffff40621c8, throw_error=true, __the_thread__=0x7ffff000c000)
at /home/dinosaur/jdk8/hotspot/src/share/vm/classfile/systemDictionary.cpp:212
#10 0x00007ffff6a87277 in SystemDictionary::initialize_wk_klass (id=SystemDictionary::ClassLoader_klass_knum, init_opt=0, __the_thread__=0x7ffff000c000)
at /home/dinosaur/jdk8/hotspot/src/share/vm/classfile/systemDictionary.cpp:1866
#11 0x00007ffff6a873a7 in SystemDictionary::initialize_wk_klasses_until (limit_id=SystemDictionary::SoftReference_klass_knum, start_id=@0x7ffff7fd0a84: SystemDictionary::Cloneable_klass_knum,
__the_thread__=0x7ffff000c000) at /home/dinosaur/jdk8/hotspot/src/share/vm/classfile/systemDictionary.cpp:1882
#12 0x00007ffff6a8b13c in SystemDictionary::initialize_wk_klasses_through (end_id=SystemDictionary::Reference_klass_knum, start_id=@0x7ffff7fd0a84: SystemDictionary::Cloneable_klass_knum,
__the_thread__=0x7ffff000c000) at /home/dinosaur/jdk8/hotspot/src/share/vm/classfile/systemDictionary.hpp:408
#13 0x00007ffff6a87553 in SystemDictionary::initialize_preloaded_classes (__the_thread__=0x7ffff000c000) at /home/dinosaur/jdk8/hotspot/src/share/vm/classfile/systemDictionary.cpp:1918
#14 0x00007ffff6a87199 in SystemDictionary::initialize (__the_thread__=0x7ffff000c000) at /home/dinosaur/jdk8/hotspot/src/share/vm/classfile/systemDictionary.cpp:1843
#15 0x00007ffff6ad68c9 in Universe::genesis (__the_thread__=0x7ffff000c000) at /home/dinosaur/jdk8/hotspot/src/share/vm/memory/universe.cpp:288
#16 0x00007ffff6ad8db6 in universe2_init () at /home/dinosaur/jdk8/hotspot/src/share/vm/memory/universe.cpp:991
#17 0x00007ffff66463b3 in init_globals () at /home/dinosaur/jdk8/hotspot/src/share/vm/runtime/init.cpp:114
#18 0x00007ffff6ab93ef in Threads::create_vm (args=0x7ffff7fd0e80, canTryAgain=0x7ffff7fd0e03) at /home/dinosaur/jdk8/hotspot/src/share/vm/runtime/thread.cpp:3424
#19 0x00007ffff6702ed0 in JNI_CreateJavaVM (vm=0x7ffff7fd0ed8, penv=0x7ffff7fd0ee0, args=0x7ffff7fd0e80) at /home/dinosaur/jdk8/hotspot/src/share/vm/prims/jni.cpp:5166
#20 0x00007ffff7bc3bda in InitializeJVM (pvm=0x7ffff7fd0ed8, penv=0x7ffff7fd0ee0, ifn=0x7ffff7fd0f30) at /home/dinosaur/jdk8/jdk/src/share/bin/java.c:1145
#21 0x00007ffff7bc1a36 in JavaMain (_args=0x7fffffffa910) at /home/dinosaur/jdk8/jdk/src/share/bin/java.c:371
#22 0x00007ffff73d66ba in start_thread (arg=0x7ffff7fd1700) at pthread_create.c:333
#23 0x00007ffff78f741d in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:109

打印hello world

这是打印hello world 的堆栈,估计是被优化了打印不了完整堆栈

(gdb) bt
#0 write () at ../sysdeps/unix/syscall-template.S:84
#1 0x00007ffff556779a in handleWrite (fd=1, buf=0x7ffff7fce270, len=12)
at /home/dinosaur/jdk8/jdk/src/solaris/native/java/io/io_util_md.c:164
#2 0x00007ffff556710a in writeBytes (env=0x7ffff000c210, this=0x7ffff7fd0398, bytes=0x7ffff7fd0390, off=0, len=12, append=0 '\000',
fid=0x47e1043) at /home/dinosaur/jdk8/jdk/src/share/native/java/io/io_util.c:189
#3 0x00007ffff555a79c in Java_java_io_FileOutputStream_writeBytes (env=0x7ffff000c210, this=0x7ffff7fd0398, bytes=0x7ffff7fd0390,
off=0, len=12, append=0 '\000') at /home/dinosaur/jdk8/jdk/src/solaris/native/java/io/FileOutputStream_md.c:70
#4 0x00007fffe10298dc in ?? ()
#5 0x0000000000000008 in ?? ()
#6 0x0000000000000008 in ?? ()
#7 0x00007ffff000c000 in ?? ()
#8 0x00007fffe02c74d8 in ?? ()
#9 0x00007fffe1028ee3 in ?? ()
#10 0x00007ffff7fd0318 in ?? ()
#11 0x00007fffe0173f60 in ?? ()
#12 0x00007ffff7fd0398 in ?? ()
#13 0x00007fffe0175120 in ?? ()
#14 0x0000000000000000 in ?? ()
(gdb) c
Continuing.
Hello, World

(gdb) bt
#0 write () at ../sysdeps/unix/syscall-template.S:84
#1 0x00007ffff556779a in handleWrite (fd=1, buf=0x7ffff7fce2d0, len=1)
at /home/dinosaur/jdk8/jdk/src/solaris/native/java/io/io_util_md.c:164
#2 0x00007ffff556710a in writeBytes (env=0x7ffff000c210, this=0x7ffff7fd0400, bytes=0x7ffff7fd03f8, off=0, len=1, append=0 '\000',
fid=0x47e1043) at /home/dinosaur/jdk8/jdk/src/share/native/java/io/io_util.c:189
#3 0x00007ffff555a79c in Java_java_io_FileOutputStream_writeBytes (env=0x7ffff000c210, this=0x7ffff7fd0400, bytes=0x7ffff7fd03f8,
off=0, len=1, append=0 '\000') at /home/dinosaur/jdk8/jdk/src/solaris/native/java/io/FileOutputStream_md.c:70
#4 0x00007fffe10298dc in ?? ()
#5 0x00007ffff7fd0410 in ?? ()
#6 0x00007ffff672dd43 in JVM_ArrayCopy (env=0x7ffff000c210, ignored=0x7ffff7fd0400, src=0x7ffff7fd03f8, src_pos=0,
dst=0x7f00f6265bea, dst_pos=1, length=0) at /home/dinosaur/jdk8/hotspot/src/share/vm/prims/jvm.cpp:298
#7 0x00007fffe1007500 in ?? ()
#8 0x0000000000000000 in ?? ()

java class file

4.1 The ClassFile Structure

A class file consists of a stream of 8-bit bytes. All 16-bit, 32-bit, and 64-bit quantities are constructed by reading in two, four, and eight consecutive 8-bit bytes, respectively. Multibyte data items are always stored in big-endian order, where the high bytes come first. In the Java SE platform, this format is supported by interfaces java.io.DataInput and java.io.DataOutput and classes such as java.io.DataInputStream and java.io.DataOutputStream.

通过jvm文档,可以知道class文件存的magic number0xCAFEBABE,存储方式是大端的

4.1 The ClassFile Structure A class file consists of a single ClassFile structure:

ClassFile {
u4 magic;
u2 minor_version;
u2 major_version;
u2 constant_pool_count;
cp_info constant_pool[constant_pool_count-1];
u2 access_flags;
u2 this_class;
u2 super_class;
u2 interfaces_count;
u2 interfaces[interfaces_count];
u2 fields_count;
field_info fields[fields_count];
u2 methods_count;
method_info methods[methods_count];
u2 attributes_count;
attribute_info attributes[attributes_count];
}

The magic item supplies the magic number identifying the class file format; it has the value 0xCAFEBABE.

dinosaur@dinosaur-X550VXK:~/jdk8/build$ hexdump  HelloWorld.class -C

使用hexdump查看class文件


00000000 ca fe ba be 00 00 00 34 00 1d 0a 00 06 00 0f 09 |.......4........|
00000010 00 10 00 11 08 00 12 0a 00 13 00 14 07 00 15 07 |................|
00000020 00 16 01 00 06 3c 69 6e 69 74 3e 01 00 03 28 29 |.....<init>...()|
00000030 56 01 00 04 43 6f 64 65 01 00 0f 4c 69 6e 65 4e |V...Code...LineN|
00000040 75 6d 62 65 72 54 61 62 6c 65 01 00 04 6d 61 69 |umberTable...mai|
00000050 6e 01 00 16 28 5b 4c 6a 61 76 61 2f 6c 61 6e 67 |n...([Ljava/lang|
00000060 2f 53 74 72 69 6e 67 3b 29 56 01 00 0a 53 6f 75 |/String;)V...Sou|
00000070 72 63 65 46 69 6c 65 01 00 0f 48 65 6c 6c 6f 57 |rceFile...HelloW|
00000080 6f 72 6c 64 2e 6a 61 76 61 0c 00 07 00 08 07 00 |orld.java.......|
00000090 17 0c 00 18 00 19 01 00 0c 48 65 6c 6c 6f 2c 20 |.........Hello, |
000000a0 57 6f 72 6c 64 07 00 1a 0c 00 1b 00 1c 01 00 0a |World...........|
000000b0 48 65 6c 6c 6f 57 6f 72 6c 64 01 00 10 6a 61 76 |HelloWorld...jav|
000000c0 61 2f 6c 61 6e 67 2f 4f 62 6a 65 63 74 01 00 10 |a/lang/Object...|
000000d0 6a 61 76 61 2f 6c 61 6e 67 2f 53 79 73 74 65 6d |java/lang/System|
000000e0 01 00 03 6f 75 74 01 00 15 4c 6a 61 76 61 2f 69 |...out...Ljava/i|
000000f0 6f 2f 50 72 69 6e 74 53 74 72 65 61 6d 3b 01 00 |o/PrintStream;..|
00000100 13 6a 61 76 61 2f 69 6f 2f 50 72 69 6e 74 53 74 |.java/io/PrintSt|
00000110 72 65 61 6d 01 00 07 70 72 69 6e 74 6c 6e 01 00 |ream...println..|
00000120 15 28 4c 6a 61 76 61 2f 6c 61 6e 67 2f 53 74 72 |.(Ljava/lang/Str|
00000130 69 6e 67 3b 29 56 00 21 00 05 00 06 00 00 00 00 |ing;)V.!........|
00000140 00 02 00 01 00 07 00 08 00 01 00 09 00 00 00 1d |................|
00000150 00 01 00 01 00 00 00 05 2a b7 00 01 b1 00 00 00 |........*.......|
00000160 01 00 0a 00 00 00 06 00 01 00 00 00 01 00 09 00 |................|
00000170 0b 00 0c 00 01 00 09 00 00 00 25 00 02 00 01 00 |..........%.....|
00000180 00 00 09 b2 00 02 12 03 b6 00 04 b1 00 00 00 01 |................|
00000190 00 0a 00 00 00 0a 00 02 00 00 00 05 00 08 00 06 |................|
000001a0 00 01 00 0d 00 00 00 02 00 0e |..........|

我们来看看hello world这个class文件的各种内容

第一个是magic number: ca fe ba be 四个字节
然后是minor_version:00 00
major_version:00 34

相关阅读