Introduced:
The previous article looks at the JDI protocol as a whole, which combines the implementation code of Eclipse to discuss the mirror mechanism of JDI.
Analysis:
The mirroring mechanism maps all data, types, domains, methods, events, states, and resources on the target virtual machine, as well as event requests sent by the debugger to the target virtual machine, to the Mirror object. The idea, like the O/R mapping we often call it, is to unify the things in 2 heterogeneous systems.
The Mirror interface is the primary interface defined in the JDI specification, which is located in the Com.sun.jdi package:
Public abstract Interface mirror{public abstract String toString (); Public abstract Virtualmachine Virtualmachine ();}
This interface provides only 2 methods, one is the string description that returns the image, and one is the virtual machine that gets the instance of the image.
The mirror mechanism defines a large interface hierarchy, and almost all of the interfaces defined in the COM.SUN.JDI package inherit the mirror interface directly or indirectly, thus mapping any elements, processes, events used in the large debug process.
For example, the value of the base type is mapped to Primitivevalue, the object instance is mapped to objectreference, and so on.
In Eclipse, it provides a mirror implementation class for Mirrorimpl, where the code that gets the mirrored virtual machine is the Read member Variable Fvirtualmachineimpl field, which is initialized in the constructor:
Public Mirrorimpl (String description) {this.fdescription = description; This.fvirtualmachineimpl = ((Virtualmachineimpl) this); PrintWriter writer = ((Virtualmachinemanagerimpl) Bootstrap.virtualmachinemanager ()). Verboseprintwriter (); if (writer = null) This.fverbosewriter = new Verbosewriter (writer); }
The virtual machine class provides many ways to obtain all the data and state information on the target virtual machine directly or indirectly, or to suspend, resume, or terminate the target virtual machine. This way the debugger can pass a mirror, then indirectly obtain the corresponding virtual machine, and send the corresponding instructions to complete the corresponding operation.
This article is from the "cohesion of parallel Lines" blog, please be sure to keep this source http://supercharles888.blog.51cto.com/609344/1587968
JPDA Architecture Studies 18-jdi's mirror mechanism