dynamic loading and dynamic extension

what exactly is the difference between dynamic loading and dynamic extension? how does the VM deals with these two and what happens in the loading and linking phase?G.P
[189 byte] By [ga11] at [2007-9-26 2:54:30]
# 1

I think what you really mean is dynamic binding vs dynamic extension.

I think dynamic loading and dynamic extension are the same: a Java program is able to decide at runtime which classes (libraries) to load even when their names are not mentioned in the code.

An example is how a browser is executed.

Dynamic binding is a synonimous for polymorphism.

Botella at 2007-6-29 10:44:03 > top of Java-index,Java HotSpot Virtual Machine,Specifications...
# 2

actully what i think is,

the jvm actually loads the classes and does a late binding ie. it links and initializes the class only upon its first use. in that case it is dynamic linking isnt it?

in dynamic extension the jvm actually downloads the class files on the fly from the network or some userdefined class loader. right?

im not sure if this is correct. so this is my doubt.

ga11 at 2007-6-29 10:44:03 > top of Java-index,Java HotSpot Virtual Machine,Specifications...
# 3

Yes I think you are right about the dynamic extension.

but :

> the jvm actually loads the classes and does a late

> binding ie.

this sentence makes me believe you have a dout with late binding, I think here you mean dynamic linking.

Dynamic linking is the process by which classes and interfaces are loaded and linked during the execution of the program. A VM can use early, late resolution or a strategy between them.

Late resolution: There is a contant pool for any class or interface the VM loads. If the VM chooses not loading the types mentioned in the symbolic references atfter having loaded the class, but rather waits until the program first uses an entry, this is late resolution. Opposed to it, a VM using early resolution loads all the types used by the program as soon as possible; that is during the third phase of the linking of a class: the resolution of its constant pool.

Dynamic (late) binding means calling the overidding method instead of the overidden in a polymorphic method.

>it links and initializes the class only

> upon its first use. in that case it is dynamic linking

> isnt it?

Obviously a type have to been loaded, linked and initialized before its firs use but:

While the exact time a class or interface is loaded and linked is implementation dependant. Both are initialized at their first active use. An active use of a type is the first ocurrence of any of these:

An object of a class is created.

The class holds the main method that start the application.

A static method is accessed.

A static field (no the final with a value known at compile time) is accessed.

Some specific methods of the reflection API are used.

Botella at 2007-6-29 10:44:03 > top of Java-index,Java HotSpot Virtual Machine,Specifications...
# 4
I forgot to mention that the initialization of a subclass is an active use of its superclass, so the superclass would be initialized as well (before the subclass).
Botella at 2007-6-29 10:44:03 > top of Java-index,Java HotSpot Virtual Machine,Specifications...
# 5

After having reviewed some parts of Inside the Java 2 Virtual machine I found the following:

Dynamic linking is the process at run time that loads and possibly links types. These types are mentioned in the constant pool of a class. This types are "hard coded" in the source code in the sense that this types were mentioned in fields access and method invocation expressions (and so on). For instance:

MyType mytype = new MyType();

This initializion of a member spawns a CONSTANT_Fieldref_info entry in the constant pool that indicates the type of the field.

I do not know c++. I think .dll are able to be loaded while the execution of the program, not only at its start.

But what c++ has not got is dynamic extension of a programan : you can load types that are not "hard coded" in the program. Via Class.forName(String) and classLoader.loadClass(String) the type named by string is loaded in a running program. The name of the class to load can be dowloaded through the internet, this is the case of Applets.

Note that the location of the class-to-load does not determine if we are talking about dynamic extension or dynamic linking:

If a class loader loaded a class from the classpath but is able as well of loading through the net when the classes to load are not in the classpath, and the class loaded from the classpath contains "hard coded" references to a class residing in a web server; the first class could utilize a class that was downloaded from the net and it was not dynamically extended.

And the other way round. A class that would use forName(String) could load the class which name is string from the local disk.

Anyway, due to the fact that dynamic linking means loading and (possibly linking) of classes by a program that is running, whenever dynamic extension is used, so dynamic linking is.

Botella at 2007-6-29 10:44:03 > top of Java-index,Java HotSpot Virtual Machine,Specifications...
# 6

>I do not know c++. I think .dll are able to be loaded while the execution of the program,

>not only at its start.

Correct.

>But what c++ has not got is dynamic extension of a programan

Perhaps too much of a mouthful there.

First C++ has nothing to do with dlls or shared libraries. C++ specifies nothing about that. The OS has to support it and you have do things in C++ with other libraries, command line options to the compiler (and linker) and with specific rules on how to write the code.

With that said, dlls/shared libraries can do late binding - how do you think JNI works? And dynamic loading of functionality is certainly not new to java. Corba and OLE/COM existed before java. And VisualBasic had OBX(right name?) a long time ago - and that was basically a bean.

And there were distributed distribution systems before java too.

Keep in mind that anything java can do, C/C++/Assembler can do. (But at least with some tasks it is probably going to require less time to code in java.)

The concepts in java aren't new. They have all been done before. But as with anything that one gets to re-write from the ground up, it is probably closer to the ideal than the previous solutions.

jschell at 2007-6-29 10:44:03 > top of Java-index,Java HotSpot Virtual Machine,Specifications...
# 7
thank you Botella and jschell, ill get back to u with more doubtsthanks again :)G.P.
ga11 at 2007-6-29 10:44:03 > top of Java-index,Java HotSpot Virtual Machine,Specifications...
# 8

> With that said, dlls/shared libraries can do late

> binding - how do you think JNI works? And dynamic

> loading of functionality is certainly not new to java.

> Corba and OLE/COM existed before java. And

> VisualBasic had OBX(right name?) a long time ago -

> and that was basically a bean.

I thought, in my previous post, had drawned a line between late binding, dynamic linking and dynamic extension. I said c++ has not got dynamic extension. I did not say anything about c++ and late binding or c++ and dynamic linking.

> And there were distributed distribution systems before

> java too.

I did not say there were not

> Keep in mind that anything java can do,

> C/C++/Assembler can do. (But at least with some tasks

> it is probably going to require less time to code in

> java.)

I think the ability to dynamically extend a running program allows java to do things that can not be done with c++ :

The applet runner within a browser can load and link to a type that is not mention in the code of the java applet runner.

An application server can load and run new versions of a java program while executing the older one in another class loader. In this way it updates java programs without having to shut down the server.

Please jschell tell me if I am wrong

Botella at 2007-6-29 10:44:03 > top of Java-index,Java HotSpot Virtual Machine,Specifications...
# 9

>> Keep in mind that anything java can do,

> >C/C++/Assembler can do.

> I think the ability to dynamically extend a

> running program allows java to do things that

> can not be done with c++ :

No. I can do anything in C++ that can be done in java. It just takes more work.

I worked on a Service creation environment(SCE) which used script files which the SCE then executed. The script files were 'written' using gui components which a user used to create the scripts. These new 'objects' could be saved and used in other scripts. All of this is done by a user at a GUI and the SCE was written in C++. Given that the scripts didn't exist until a user created them in the GUI, I don't know how much more 'late' you can get on the binding.

This is about the same thing people want to do when developers ask here about getting a java application to compile and then run a class file.

Microsoft has(had?) DCOM which essentially stood for Distributed COM objects. Basically like a RMI server. Clients would make requests to the server, which could be updated on the fly. All of this was in C++.

jschell at 2007-6-29 10:44:03 > top of Java-index,Java HotSpot Virtual Machine,Specifications...