An Energy Consumption Model for Java Virtual Machine - CiteSeerX

4 downloads 398 Views 210KB Size Report
uct to market on time make the use of high-level languages like Java necessary. ... Java technology makes it possible to develop applications, ..... As the new opcode allocates the same amount of memory for all ..... IEEE Intnl. Workshop on LPD, Napa, CA, 1994. .... Turku School of Economics and Business Administration.
An Energy Consumption Model for Java Virtual Machine Sébastien Lafond Johan Lilius Åbo Akademi University, Department of Computer Science, Lemminkäisenkatu 14A, FIN-20520 Turku, Finland

Turku Centre for Computer Science TUCS Technical Report No 597 March 2004 ISBN 952-12-1320-5 ISSN 1239-1891

Abstract In recent years we have seen an explosion of markets for portable electronic devices such as PDAs, personal communicators and mobile phones. The size and complexity of applications, but also development constraints like getting the product to market on time make the use of high-level languages like Java necessary. Java 2 Micro Edition (J2ME) has emerged as a good solution for developing applications on those platforms. The main goal of Java language is to allow applications development with an abstraction of the target platform, making the concept “write once, run it anywhere” possible. The Java Virtual machine (JVM) is an abstract machine, making the interface between platform independent applications and the hardware, through a possible operating system. Thus the use of Java language can be seen as adding one more layer, the Java virtual machine, between the hardware and software layers. In this paper we establish a general framework for estimating the energy consumption of an embedded Java virtual machine. We have designed a number of experiments to find the constants overhead of the Virtual Machine and establish energy consumption cost for individual Java Opcodes. The results show that there is a basic constant overhead that is equal for every Java program, and a that a subset of Java opcodes have an almost constant energy cost. We also show that memory access is a crucial energy consumption component.

Keywords: Java virtual machine, KVM, energy comsumption, opcode, bytecode

TUCS Laboratory Embedded Systems Laboratory

Contents 1 Introduction

2

2 Energy Distribution in Handheld Devices 2.1 Definitions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2.2 Solutions for low power systems . . . . . . . . . . . . . . . . . .

2 3 4

3 An energy consumption model of Java applications 7 3.1 Measurements methodology . . . . . . . . . . . . . . . . . . . . 8 3.1.1 KVM enprofiler . . . . . . . . . . . . . . . . . . . . . . . 10 4 Experiments 4.1 First experiment . . . . . . . . . . . 4.2 Second experiment . . . . . . . . . 4.3 Third experiment . . . . . . . . . . 4.4 Other experiments . . . . . . . . . . 4.5 Java opcode energy cost . . . . . . . 4.5.1 Measurements methodology 4.5.2 Results . . . . . . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

11 11 12 14 14 16 17 18

5 Conclusion

19

A Annex

23

1

1 Introduction In recent years we have seen an explosion of markets for portable electronic devices such as PDAs, personal communicators and mobile phones. These batteryoperated devices provide more and more functionalities and as a consequence become more and more complex. They have in common strong constraints on energy consumption, and thus maximizing battery life for such devices is crucial. Several techniques have been developed to optimize the energy consumption of embedded systems. Those techniques can be hardware based solutions, as well as software or co-design solutions [1]. Until now, techniques for low power optimization of software have been mostly applied on processor instructions level [2, 3, 4] by using principally processor specific instructions [5, 6]. Techniques on memory management have also been widely applied for optimizing energy consumption [7, 8, 9, 10]. Manufacturers have now understood the fact that software optimization for lower energy consumption is an important issue. A typical example is the story of the Siemens C25 "power" [11]. The size and complexity of applications, but also development constraints like getting the product to market on time make the use of high-level languages like Java necessary. Java 2 Micro Edition (J2ME) has emerged as a good solution for developing applications on those platforms. Due to the wide diversity of hardware and OS used in the world of handheld devices, portability across systems is not easy and needs efforts. Java technology makes it possible to develop applications, usable by a range of different systems and platforms, without having to worry about portability. We can easily predict that developer communities and companies will more and more provide Java applications for such handheld devices, to satisfy an increasing demand. But fewer studies have been done on energy consumption from the virtual machine level. The study of energy consumption of Java applications is needed to build an energy consumption model of the virtual machine. This model will be use to quantify the energy needed by the applications.

2 Energy Distribution in Handheld Devices We mostly know problems related to power dissipation through the noisy fans and the more and more sophisticated cooling systems that need to be installed on modern PC processors. As the number of transistors integrated on one chip increased, the power dissipation follows the same trend. For an Intel Pentuim IV on 90 process the power dissipation can reach 115 watts and drain up to 91 amperes through its 86 processor supply voltage pins. But as soon as a system require being mobile and autonomous those extreme values make a Pentuim IV 2

I

Dipole

U Figure 1: Convention for current and voltage notation for a dipole in a DC circuit unusable over standard batteries characteristics. For such system giving consideration to its energy consumption is crucial, so we will look in this section at basic concepts about electrical power and energy and review different solution for low power systems.

2.1 Definitions Using the current and voltage notation convention as show in figure 1, we can define the instantaneous power for a dipole in a direct current (DC) circuit as the following :

 

     

where     is the instantaneous power in Watt (W) dissipated by one dipole  at time , the potential difference in Volt (V) across his inputs at time , and  

 the current in Ampere (A) passing through the dipole at time .   ! The average power  dissipated by one dipole between the time and in Watt, is defined by : " 

# ! $% 

&('*) ',+

 - .0/1



where the function of the potential difference in Volt across his inputs, and 

the function of the current in Ampere passing through the dipole. 3 ! The energy 2 , in Joule (J), consumed by one dipole between the time and is defined by : 2



&('*) ',+

 - .0/1

The energy is a measure of power expended over time. In other words one Joule is equivalent to one watt dissipated or radiated during one second. The misuses of terms Energy and Power in the literatures have often lead to confusion. In this document we will try to respect their definitions, with only one 3

Energy consumed

Power

t0

E

1

t1 Time

t0

t1 Time

Power

Energy consumed

Figure 2: System A - Power dissipation and energy consumed

t0

E'

t1 Time

1

t0

t1 Time

Figure 3: System B - Power dissipation and energy consumed exception concerning the term "low power" which already has been adopted by the community as meaning "low average power".

2.2 Solutions for low power systems In order to extend the battery life of an handheld device two solutions can be applied: increase the amount of energy embedded in the device, or decrease its energy consumption. Much effort has been put into increasing the batteries capacity, but solutions are costly in terms of price, volume and weight [12]. Therefore the attention has been turn to develop so called Low Power Systems. Energy saving can be obtained by specific hardware implementations and, or, by techniques for low power optimization of software [13]. In this section we will look at system level and software solutions that can be applied once the hardware implementation has been defined. The power dissipated by one CMOS component is proportional to the square of its supply voltage 4565 , to his frequency 7 in Hertz (Hz) , its lumped capacitance 8 ;: in Farad (F), its activity factor 9 and its leakage current : 8 " D:- 9=< 7?4 565A@ 4B565C< 4

D: where 4B565C< represent the static power (dissipated due to the leakage current), 8 and 9=< 7E duplicate the reference of the new object in the operand stack 11 invokespecial #3 -> call the constructor 14 pop -> remove the top of the operand stack 17 iinc 2 1 -> increment the second local variable by 1 18 iload_2 -> load the second local variable in the operand stack (i) 19 iload_1 > load the first local variable in the operand stack (length) 20 if_icmple 65543 .....

Figure 11: Second experiment - Java opcodes corresponding to the for loop and trigger off a garbage collection. It is also important to notice that the energy consumed by the interpreter stage is linear and proportional to the loop length. This can be explain by the fact that the interpreter is looping over a number of constant Java opcodes, see figure 11. The KVM enprofiler evaluate the cost of memory access according to the memory technology, i.e. have for each memory type (RAM, ROM, Flash, etc.) an average cost for each access type regardless of its address. As the new opcode allocates the same amount of memory for all objects created, it will have an identical cost for each execution.

The energy distribution for a loop length of 1000, see figure 12, is similar to the first experiment with an interpreter stage even more dominant, representing over 95% of the total energy consumed. If we compare the numerical values of StartJVM, KVM_Start and KVM_Clean stages with the one obtained during the first experiment, we note that they are identical. This shows that constant overhead 13

Energy Distribution

Memory/Instructions Distribution

1.42%

29.93%

Instructions

StartJVM Inst StartJVM Mem

Memory

KVM Start Inst

28.59%

KVM Start Mem Interpret Inst Interpret Mem KVM Clean Instr KVM Clean Mem Garbage Inst Garbage Mem

70.07%

67.16%

Figure 12: Second experiment - Energy distribution for a loop length equal to 1000 costs can be define for some of the KVM stages, as they behave independently from the Java application running on KVM.

4.3 Third experiment The third experiment runs a Java class which implements a basic arithmetic operation, see figure 13 for the class source code. In figure 14 the distribution of energy consumed by processor instructions and memory access is identical to the one obtained during the second experiment. This observation suggests that running an arithmetic operation or object instantiation dominant application will not influence the energy distribution between processor instructions and memory access. The consumed energy distribution is also similar to the preceding one with the overall interpreter stage contribution lightly lower at 85%. This difference is explained by the lower energy value consumed to interpret this third Java class. As some other stages seem to have a constant energy consumption, the interpreter stage size decrease in the energy distribution. Figure 15 shows the relation between the energy consumed by the application and the loop length. The graph is similar to the precedent one with constant values for all stages except for the interpreter. For the same reasons as experiment 2, the energy consumed by the interpreter is linear in the loop length. But its instruction and memory slopes are about five times lower as the Java opcodes needed to increment one integer consume less energy than the one needed to instantiate one MyClass object.

4.4 Other experiments We run numerous other Java classes through the KVM enprofiler and all observations on their results were similar to one described above. That is, some KVM 14

public class MyClass2 { public static void main(String arg[]) { int length = X; int i=0; for(int number=0;number