A method and a corresponding
system (200) for metering execution of interpreted programs (220) are proposed. Typically, an
interpreter, such as the
Java Virtual Machine (215), lacks built-in capabilities for communicating with the hardware and
software platform of the computer directly; for this purpose, the
virtual machine invokes external native functions through the
Java Native Interface (225). The solution of the invention is based on the idea of stubbing the dynamic libraries (235) that implement those native functions. Therefore, when the
virtual machine needs a native function (for example, to load a new class), a stub
library (250) is loaded in place of the required dynamic
library. As soon as the
virtual machine calls the desired command, the stub
library takes control and identifies the interpreted program that is run by the virtual
machine; preferably, this operation is performed by querying a catalogue that associates the new class with the corresponding interpreted program. The stub library then loads the dynamic library and forwards the required command. In a different embodiment, the class
loader is replaced with a stub module. In this case, the stub class
loader detects the loading of the class including a main method of the interpreted program; the main method is then updated by inserting a call to a licensing agent, in order to identify the interpreted program when the main method is actually executed.