Top Banner
Overall Aspects of Java Native Threads on Win32 Platform Bala Dhandayuthapani Veerasamy 1,and G. M. Nasira 2 1 Research Scholar in Information Technology, Manonmaniam Sundaranar University, Tirunelveli, Tamil Nadu, India. 2 Assistant Professor in Computer Science, Chikkanna Govt. Arts College, Tirupur, Tamil Nadu, India. e-mail: [email protected], [email protected] Abstract. A parallel programming model is a set of software technologies to articulate parallel algorithms and match applications with the underlying parallel systems. It surroundings with applications, languages, libraries, compilers, communication systems, and parallel I/O. Programmer have to decide a proper parallel programming model or a form of mixture of them to develop their parallel applications on a particular platform. Multithreaded programming is written in many programming languages with usually increased performance. Thread libraries can be implicit or explicit. OpenMP, MPI, Intel Threading Building Blocks (TBB) are implicit thread libraries. Pthreads and Windows Threads are explicit thread libraries. Threads can be accessed by different programming interfaces. Many software libraries provide an interface for threads usually based on POSIX Threads, Windows threads, OpenMP, MPI and Threading Building Blocks frameworks. These frameworks provide a different level of abstraction from the underlying thread implementation of the operating system. The general parallelism is the execution of separate tasks in parallel. These multithreading libraries provide difference features. For example, Java support flexible and easy use of threads; yet, java does not have contained methods for thread affinity to the processors; because, green threads are scheduled by the virtual machine itself where as Windows or POSIX thread can fix thread affinity. The native threads are scheduled by the operating system that is hosting the virtual machine. This research finding carry overview aspects on how Java can facilitate Win32, POSIX, TBB threads through JNI, which enables Java threads, to add other threading library features in Java. Keywords: Affinity mask, Intel TBB, JNA, JNI, Kernel, Multithread, NativePthread, Pthread, Win32 API. 1. Introduction A multi-core is an architecture [1–8] design that places multiple processors on a single die (computer chip). Each processor is called a core. As chip capacity increased, placing multiple processors on a single chip became practical. These designs are known as Chip Multiprocessors (CMPs) because they allow for single chip multiprocessing. Multi-core is simply a popular name for CMP or single chip multiprocessors. The concept of single chip multiprocessing is not new, and chip manufacturers have been exploring the idea of multiple cores on a uniprocessor since the early 1990s. Recently, the CMP has become the preferred method of improving overall system performance. Manufacturers are increasingly adding more processor core is often a highly efficient way to buy more power at low incremental cost. Of course our main purpose in writing parallel programs is usually increased performance. Parallelism is a proven way to run programs fast. This is a departure from the approach of increasing the clock frequency or processor speed to achieve gains in overall system performance. Increasing the clock frequency has started to hit its limits in terms of cost - effectiveness. CMPs [7] come in multiple flavors: two processors (dual core), four processors (quad core), and eight processors (octa core) configurations. Some configurations are multithreaded; some are not. There are several variations in how cache and memory are approached in the new CMPs. The approaches to processor to processor communication vary among different implementations. Several parallel computing platforms focused on particular multi-core platforms, offer a shared address space. A natural programming model for multi-core architectures is a thread model, in which all threads have access to shared variables. These shared variables are then used for information and data exchange. Corresponding author © Elsevier Publications 2014. 667
9

Overall Aspects of Java Native Threads onWin32 Platform

Mar 10, 2023

Download

Documents

Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Overall Aspects of Java Native Threads onWin32 Platform

Overall Aspects of Java Native Threads on Win32 Platform

Bala Dhandayuthapani Veerasamy1,∗ and G. M. Nasira2

1Research Scholar in Information Technology, Manonmaniam Sundaranar University, Tirunelveli, Tamil Nadu, India.2Assistant Professor in Computer Science, Chikkanna Govt. Arts College, Tirupur, Tamil Nadu, India.

e-mail: [email protected], [email protected]

Abstract. A parallel programming model is a set of software technologies to articulate parallel algorithms andmatch applications with the underlying parallel systems. It surroundings with applications, languages, libraries,compilers, communication systems, and parallel I/O. Programmer have to decide a proper parallel programmingmodel or a form of mixture of them to develop their parallel applications on a particular platform. Multithreadedprogramming is written in many programming languages with usually increased performance. Thread librariescan be implicit or explicit. OpenMP, MPI, Intel Threading Building Blocks (TBB) are implicit thread libraries.Pthreads and Windows Threads are explicit thread libraries. Threads can be accessed by different programminginterfaces. Many software libraries provide an interface for threads usually based on POSIX Threads, Windowsthreads, OpenMP, MPI and Threading Building Blocks frameworks. These frameworks provide a different levelof abstraction from the underlying thread implementation of the operating system. The general parallelism is theexecution of separate tasks in parallel. These multithreading libraries provide difference features. For example,Java support flexible and easy use of threads; yet, java does not have contained methods for thread affinity tothe processors; because, green threads are scheduled by the virtual machine itself where as Windows or POSIXthread can fix thread affinity. The native threads are scheduled by the operating system that is hosting the virtualmachine. This research finding carry overview aspects on how Java can facilitate Win32, POSIX, TBB threadsthrough JNI, which enables Java threads, to add other threading library features in Java.

Keywords: Affinity mask, Intel TBB, JNA, JNI, Kernel, Multithread, NativePthread, Pthread, Win32 API.

1. Introduction

A multi-core is an architecture [1–8] design that places multiple processors on a single die (computer chip). Eachprocessor is called a core. As chip capacity increased, placing multiple processors on a single chip became practical.These designs are known as Chip Multiprocessors (CMPs) because they allow for single chip multiprocessing.Multi-core is simply a popular name for CMP or single chip multiprocessors. The concept of single chipmultiprocessing is not new, and chip manufacturers have been exploring the idea of multiple cores on a uniprocessorsince the early 1990s. Recently, the CMP has become the preferred method of improving overall system performance.Manufacturers are increasingly adding more processor core is often a highly efficient way to buy more power atlow incremental cost. Of course our main purpose in writing parallel programs is usually increased performance.Parallelism is a proven way to run programs fast. This is a departure from the approach of increasing the clockfrequency or processor speed to achieve gains in overall system performance. Increasing the clock frequency hasstarted to hit its limits in terms of cost - effectiveness.

CMPs [7] come in multiple flavors: two processors (dual core), four processors (quad core), and eight processors(octa core) configurations. Some configurations are multithreaded; some are not. There are several variations in howcache and memory are approached in the new CMPs. The approaches to processor to processor communication varyamong different implementations. Several parallel computing platforms focused on particular multi-core platforms,offer a shared address space. A natural programming model for multi-core architectures is a thread model, in whichall threads have access to shared variables. These shared variables are then used for information and data exchange.

∗Corresponding author

© Elsevier Publications 2014. 667

Page 2: Overall Aspects of Java Native Threads onWin32 Platform

Bala Dhandayuthapani Veerasamy and G. M. Nasira

To coordinate the access to shared variables, synchronization mechanisms have to be used to avoid race conditions incase of concurrent accesses.

Parallel programming environments [1–8] provide the basic tools, language features, and application programminginterfaces (APIs) needed to construct a parallel program. A programming environment [1–8] implies a particularabstraction of the computer system called a programming model. Programming models too closely aligned toa particular parallel system lead to programs that are not portable between parallel computers. Because theeffective lifespan of software is longer than that of hardware, many organizations have more than one type ofparallel computer, and most programmers insist on programming environments that allow them to write portableparallel programs. Also, explicitly managing large numbers of resources in a parallel computer is difficult,suggesting that Higher-level abstractions of the parallel computer might be useful. Multithreaded programexpected to exploit multi-core environments. The green threads are scheduled by the virtual machine itself. Thisis the original model for Java Virtual Machine mostly follows the idealized priority based scheduling. Thiskind of thread never uses operating system threads library. The native threads are scheduled by the operatingsystem that is hosting the virtual machine. The operating system threads are logically divided into user levelthreads and system level threads. The operating system itself that is the kernel of the operating system lies atsystem level threads. In a user thread model, on the other hand, the application code implements the threadoperations.

2. Java Threads Libraries

The Class java.lang.Thread [9–13]: The class Thread defines thread objects. When the start() method is called, anactual running thread is created which the Thread object can control. It is important to distinguish between the object(which is just memory and a set of methods) and the running thread (which executes code). All static thread methodsapply to the current thread. There is a second method of creating a Java thread. In this method you write a class thatimplements the Runnable interface, defining a run()method on it. You then create a thread object with this Runnableas the argument and call start() on the thread object.

The java.util.concurrent API [9–13]: Java 7 introduced ExecutorService, manages a pool of threads and allowsus to schedule tasks for execution by threads in its pool. It is, however, up to us to decide how many threadswill be in the pool, and there is no distinction between tasks we schedule and subtasks these tasks create. Java 7brings a specialization of ExecutorService with improved efficiency and performance the fork-join API [14]. TheForkJoinPool class dynamically manages threads based on the number of available processors and task demand.Fork-join employs work-stealing where threads pick up (steal) tasks created by other active tasks. This provides betterperformance and utilization of threads. Subtasks created by active tasks are scheduled using different methods thanexternal tasks. We’d typically use one fork-join pool in an entire application to schedule tasks. Also, there’s no needto shut down the pool since it employs daemon threads. To schedule tasks, we provide instances of ForkJoinTask(typically an instance of one of its subclasses) to methods of ForkJoinPool. ForkJoinTask allows us to fork tasksand then join upon completion of the task. ForkJoinTask has two subclasses: RecursiveAction and RecursiveTask.To schedule tasks that don’t return any results, we use a subclass of RecursiveAction. For tasks that return results,we use a subclass of RecursiveTask. The fork-join API is geared toward tasks that are reasonably sized so the costis amortized but not too large (or run indefinitely in loops) to realize reasonable throughput. The fork-join APIexpects tasks to have no side effects (don’t change shared state) and no synchronized or blocking methods. Thefork-join API is very useful for problems that can be broken down recursively until small enough to run sequentially.The multiple smaller parts are scheduled to run at the same time, utilizing the threads from the pool managedby ForkJoinPool.

ParallelArray [15]: Java 8 introduced ParallelArray, encapsulates a ForkJoinExecutor and an array in orderto provide parallel aggregate operations. The main operations are to apply some procedure to each element, tomap each element to a new element, to replace each element, to select a subset of elements based on matchinga predicate or ranges of indices, and to reduce all elements into a single value such as a sum. A ParallelArray isnot a List, but can be viewed as one, via method asList(), or created from one, by constructing from array returnedby a list’s toArray method. Arrays differ from lists in that they do not incrementally grow or shrink. Randomaccessibility across all elements permits efficient parallel operation. ParallelArrays also support element-by-elementaccess (via methods get and/set), but are normally manipulated using aggregate operations on all or selectedelements.

668 © Elsevier Publications 2014.

Page 3: Overall Aspects of Java Native Threads onWin32 Platform

Overall Aspects of Java Native Threads on Win32 Platform

3. Java Native Threads Models

Using Java Native Interface (JNI) [16,17]: Java Native Interface (JNI) is a strong feature of the Java platform.An application that uses the JNI can incorporate native codes written in other programming languages such as C andC++. The JNI is a strong feature that permits us to take benefits of the Java platform, but still uses code written inother languages. As a part of the Java Virtual Machine implementation, the JNI is a two-way interface that permitsJava applications to invoke native code and vice versa. The JNI is designed to unite Java applications with native code.As a two-way interface, the JNI can support two types of native code: native libraries and native applications.

JNI allows writing native methods that allow Java applications to call functions implemented in native libraries.Java applications call native methods in the same way that they call methods implemented in the Java programminglanguage. Behind the scenes, however, native methods are implemented in other language and reside in native libraries.In order to write Java Native Interface application that calls a C or C++ function, consists of the following steps:

1. Declaring Native Methods in Java Class2. Compiling Java Class and Creating Native Method Header3. Implementing Native Method4. Compiling the C++ Source and Creating Native Library5. Testing Native Program

Using Java Native Access (JNA) [18]: It can download from https://jna.java.net. JNA makes Java programs easyaccess to native shared libraries without using the Java Native Interface. JNA’s design aims to provide native accessin a natural way with a minimum of effort. The JNA library uses a small native library called foreign functioninterface library (libffi) to dynamically invoke native code. The JNA library uses native functions allowing code toload a library by name and retrieve a pointer to a function within that library, and uses libffi library to invoke it, allwithout static bindings, header files, or any compile phase. The developer uses a Java interface to describe functionsand structures in the target native library. This makes it quite easy to take advantage of native platform features withoutincurring the high development overhead of configuring and building JNI code. JNA is built and tested on Mac OS X,Microsoft Windows, FreeBSD/OpenBSD, Solaris, and Linux. It is also possible to tweak and recompile the native buildconfigurations to make it work on other platforms. Java Native Access lets you access C libraries programmatically.In situations where Java does not provide the necessary APIs, it is sometimes necessary to use the Java Native Interface(JNI) to make platform-specific native libraries accessible to Java programs.

JNA approaches to integrate native libraries with Java programs. It shows how JNA enables Java code to call nativefunctions without requiring glue code in another language. It is useful to know JNA, because the Java APIs withtheir architecture-neutral emphasis will never support platform specific functionality. Though Java itself is architectureneutral, JNA is perforce on platform-specific. The Java Native Access project is hosted on Java.net, where you candownload the project’s online Javadoc and the software itself. Although the download section identifies five JAR files,you only need to download jna.jar. The jna.jar file provides the essential JNA software and is required to run all of theexamples you’ll find here. This JAR file contains several packages of classes, along with JNI-friendly native librariesfor the UNIX, Linux, Windows, and Mac OS X platforms. Each library is responsible for dispatching native methodcalls to native libraries. Here are a few things you have to take care of when starting a JNA project:

1. Download jna.jar from the JNA project site and add it to your project’s build path. This file is the only JNAresource you need. Remember that jna.jar must also be included in the run-time classpath.

2. Find the names of the DLLs that your Java code will access. The DLL names are required to initialize JNA’slinkage mechanisms.

3. Create Java interfaces to represent the DLLs such as kernel32.dll, user32.dll and etc on your application that willaccess.

4. Test linkage of your Java code to the native functions.

4. Implicit Threading

Implicit threading libraries [7] take care of much of the minutiae needed to create, manage and synchronize threads.There are algorithms written concurrently to take advantage of the limited scope of features within the implicitlibraries. These threading libraries are compiler directives. There are three renowned implicit libraries focused here.

OpenMP [19]: It is a set of language extensions implemented as compiler directives. Implementations are currentlyavailable for FORTRAN, C, and C++. OpenMP is frequently used to incrementally add parallelism to sequential code.

© Elsevier Publications 2014. 669

Page 4: Overall Aspects of Java Native Threads onWin32 Platform

Bala Dhandayuthapani Veerasamy and G. M. Nasira

It consists of compiler directives, library routines and environment variables that specify shared-memory concurrencyin FORTRAN, C, and C++ programs. The rationale behind the development of OpenMP was to create a portable andunified standard of shared-memory parallelism. All major compilers support the OpenMP language. This includes theMicrosoft Visual C/C++ .NET for Windows and the GNU GCC compiler for Linux. The Intel C/C++ compilers, forboth Windows and Linux, also support OpenMP. OpenMP directives demarcate code that can be executed in paralleland control how code is assigned to threads. The threads in an OpenMP code operate under the fork-join model.

OpenMP for Java is JaMP [20], which can download from https://www2.cs.fau.de/EN/research/JavaOpenMP/index.html. JaMP is an implementation of the well-known OpenMP standard adapted for Java. JaMP allows oneto program, for example, a parallel for loop or a barrier without resorting to low-level thread programming. JaMPcurrently supports all of OpenMP 2.0 with partial support for 3.0 features, e.g., the collapse clause. JaMP generatespure Java 1.5 code that runs on every JVM. It also translates parallel for loops to CUDA-enabled graphics cards forextra speed gains. If a particular loop is not CUDA-able, it is translated to a threaded version that uses the cores ofa typical multi-core machine. JaMP also supports the use of multiple machines and compute accelerators to solvea single problem. This is achieved by means of two abstraction layers. The lower layer provides abstract computedevices that wrap around the actual CUDA GPUs, OpenCL GPUs, or multi-core CPUs, wherever they might be ina cluster. The upper layer provides partitioned and replicated arrays. A partitioned array automatically partitions itselfover the abstract compute devices and takes the individual accelerator speeds into account to achieve an equitabledistribution. The JaMP compiler applies code-analysis to decide which type of abstract array to use for a specific Javaarray in the user’s program.

MPI [21]: it is a set of library routines that provide for process management, message passing, and some collectivecommunication operations. The operations are involving all the processes involved in a program, such as barrier,broadcast, and reduction. MPI programs can be difficult to write because the programmer is responsible for datadistribution and explicit inter-process communication using messages. Because the programming model assumesdistributed memory, MPI is a good choice for MPPs and other distributed memory machines.

MPI for Java is Open MPI [22], which can download from http://www.open-mpi.org. The Java interface is providedin Open MPI on a provisional basis. It is not part of the current or any proposed MPI standard. Continued inclusion ofthe Java interface is contingent upon active user interest and continued developer support. The decision to add a Javainterface to Open MPI was motivated by a request from the Hadoop community. Hadoop is a Java-based environmentfor processing extremely large data sets. Modeled on the Google enterprise system, it has evolved into its own rapidlygrowing open-source community. Although executed in parallel, Hadoop processes are independent and thus wouldonly possibly use MPI as a base for efficient messaging. Of greater interest, however, is the ability to add MPI-basedfollow-on processing to a Hadoop map-reduce operation. Since Hadoop map-reduce is typically done in Java, anysubsequent MPI operations would best be done in that language.

MPJ Express [23]: It is an open source Java message passing library that allows application developers to write andexecute parallel applications for multi-core processors and compute clusters/clouds. MPJ Express enables HPC usingJava. Earlier efforts for building a Java messaging systems have typically followed either the JNI approach, or thepure Java approach. On commodity platform like Fast Ethernet, advances in JVM technology now enable networkingapplications written in Java to rival their C counterparts. On the other hand, improvements in specialized networkinghardware have continued, cutting down the communication costs to a couple of microseconds. Keeping both in mind,the key issue at present is not to debate the JNI approach versus the pure Java approach, but to provide a flexiblemechanism for applications to swap communication protocols

Intel Threading Building Blocks [24–29]: Intel TBB can download from https://www.threadingbuildingblocks.org.It is a C++ template-based library for loop-level parallelism that concentrates on defining tasks rather than explicitthreads. The components of TBB include generic parallel algorithms, concurrent containers, low-level synchronizationprimitives, and a task scheduler. Programmers using TBB can parallelize the execution of loop iterations by treatingchunks of iterations as tasks and allowing the TBB task scheduler to determine the task sizes, number of threads touse, assignment of tasks to those threads, and how those threads are scheduled for execution. The task scheduler willgive precedence to tasks that have been most recently in a core with the idea of making best use of the cache that likelycontains the task’s data. The task scheduler utilizes a task-stealing mechanism to load balance the execution.

Intel TBB assisted us create applications that collect the benefits of new processors with more and more cores asthey become available. It uses templates for common parallel iteration patterns, enabling us to attain increased speedfrom multiple processor cores without having to be experts in synchronization, load balancing, and cache optimization.Intel TBB promotes scalable data parallel programming. The data parallelism has a special significance in the era

670 © Elsevier Publications 2014.

Page 5: Overall Aspects of Java Native Threads onWin32 Platform

Overall Aspects of Java Native Threads on Win32 Platform

of the multi and many-core computing, where huge numbers of cores are available on single chip devices. The dataparallelism is concerned mainly with operations on arrays of data. The data parallelism involves sharing common dataamong executing processes through memory coherence, improving performance by reducing the time required to loadand access memory.

We exercised Intel TBB win32 [30] through JNI to utilize in Java. This contribution exploited painless usage of IntelTBB parallel algorithms used in Java. In this research, we especially focused on utilizing parallel−for algorithms withblocked−range, which supply an iterator that determines how to make a task split in half when the task is consideredlarge enough. In turn, Intel TBB will then divide large data ranges repeatedly to help spread work evenly amongprocessor cores. The parallel−for loop constructs deserved overhead cost for every chunk of work that it schedules.It chooses chunk sizes automatically, depending upon load balancing needs. The blocked−range supported to workwith single dimensional array. Thus, we illustrated manipulating array on single dimensional and the speedup andperformance improvements demonstrated. If some other operations required performing on one dimensional array, weare expected to change the code on NativeTBB.cpp program. At present, there are opportunities to work with twodimensional arrays through using blocked−range2d and three-dimensional arrays through using blocked−range3d.Not only the parallel−for loop can be used in java, but also there are huge openings for utilizing the entire Intel TBBparallel library template that can be used for various purposes.

5. Explicit Threading

Explicit threading libraries [7] require the programmer to control all aspects of threads, including creating threads,associating threads to functions, and synchronizing and controlling the interactions between threads and sharedresources. The two most prominent threading libraries in use today are POSIX threads (Pthreads) and WindowsThreads by Microsoft. While the syntax is different between the two APIs, most of the functionality in one model canbe found in the other. Each model can create and join threads, and each features synchronization objects to coordinateexecution between threads and control the access to shared resources by multiple threads executing concurrently. Let’sstart with Pthreads for readers who use Linux.

Pthreads [31,32]: Pthreads has a thread container data type of pthread−t. Objects of this type are used to referencethe thread (borrowing terms from Windows Threads, I tend to call this object the handle of the created thread). To createa thread and associate it with a function for execution, use the pthread−create() function. A pthread−t handle is returnedthrough the parameter list. When one thread needs to be sure that some other thread has terminated before proceedingwith execution, it calls pthread−join(). The calling thread uses the handle of the thread to be waited on as a parameterto this function. If the thread of interest has terminated prior to the call, pthread−join() returns immediately with thethreaded function’s exit code (if any) from the terminated thread; otherwise, the calling thread is blocked until thatcurrently executing thread has completed.

Pthreads for Java is Pthreads-w32 [33], which can download from https://www.sourceware.org/pthreads-win32/index.html. The POSIX 1003.1-2001 standard defines an application programming interface (API) for writingmultithreaded applications. This interface is known more commonly as Pthreads. A good number of modern operatingsystems include a threading library of some kind: Solaris (UI) threads, Win32 threads, DCE threads, DECthreads, orany of the draft revisions of the Pthreads standard. The trend is that most of these systems are slowly adopting thePthreads standard API, with application developers following suit to reduce porting woes. Win32 does not, and isunlikely to ever, support Pthreads natively. This project seeks to provide a freely available and high-quality solutionto this problem. Various individuals have been working on independent implementations of this well-documentedand standardized threading API, but most of them never see the light of day. The tendency is for people to onlyimplement what they personally need, and that usually does not help others. This project attempts to consolidate theseimplementations into one implementation of Pthreads for Win32.

We exercised Pthread-w32 [34] through JNI to utilize in Java. The native threads are scheduled by the operatingsystem that is hosting the virtual machine. The user level Pthreads has used the kernel of the operating system lies atsystem level threads. The kernel is accountable for managing system calls on behalf of programs that run at user levelPthreads. This research finding focused on how Java can facilitate Pthreads through JNI, which enables Java threadsand native threads to schedule and execute in hybrid mode. As a result, this research brings up opening to exploitPthreads within Java program, it is strongly recommending for Flynn’s Multiple Program Multiple Data (MPMD) andMultiple Program and Single Data (MPSD) through method level concurrency.

Java support flexible and easy use of threads; yet, java does not contain methods for thread affinity to the processors.Setting an affinity [35] thread to multiprocessor is not new to research, since it was already sustained by other

© Elsevier Publications 2014. 671

Page 6: Overall Aspects of Java Native Threads onWin32 Platform

Bala Dhandayuthapani Veerasamy and G. M. Nasira

multiprogramming languages for example C in UNIX platform and C# in Windows platform. We exercised Javamultithreaded program adapt with an affinity thread on multiprocessors in windows platforms [36]. Java nativePthreads for windows can also support setting affinity thread through pthread attr−setaffinity−np(. . . ) method, thefollowing syntax of the method is shown bellow.

The sample following sample code declares the native method in java class for setting affinity thread. Once we declarednative methods, we should compile java class and create native method header file.

Dev-C++ allows creating Dynamic Link Library (DLL), is a shared library that contains the native code. In orderto create dll, we should choose DLL project, which should be linked libpthread.a(pthreads-win32). First of all theprogram should be imported with JNT.Win32.Kernel.NativePthread; this package library included a line of code thatloaded a native library into the program through System.load (“NativePthread.dll”). The pthread.dll (pthreads-win32)should be placed in windows/system32 folder. When program started execution the public static void main(String[]args) is called JVM to creates the main thread. Inside the TestMain class constructor, we called createPthread()to create Pthreads, will automatically call the public void executeNativePthread() to execute our parallel task. ThesetPthreadAffinityMask() method assign the thread affinity on processor core. This program is evaluated on core 2Duo environment by selecting different affinity on CPU. The following figure 1 shows the performance with 100%utilization of CPU.

Windows Threads [37,38]: Windows Threads uses the ubiquitous kernel object HANDLE type for the handle ofa thread. The −beginthreadex() function is recommended for creating a thread, especially if the code will be using the

672 © Elsevier Publications 2014.

Page 7: Overall Aspects of Java Native Threads onWin32 Platform

Overall Aspects of Java Native Threads on Win32 Platform

Figure 1. CPU performance.

C runtime library. The return value of this function will need to be cast to HANDLE. The alternate CreateThread()function returns the HANDLE of a spawned thread. These two functions have the exact same set of parameters, but theformer is safer to use with regard to initialization of thread resources and more reliable in the reclamation of allocatedresources at thread termination. The can be controlled within standard C library, but scheduling thread can be done onlythrough windows kernel. The Microsoft Windows Application Programming Interface (API) [38] facilitates functionsused by all Windows based applications. Most of the functions are generally supported on 32-bit and 64-bit Windows.This API is designed for use by C/C++ programmers. We can develop our application with a graphical user interface;access system resources such as memory and devices; display graphics and formatted text; incorporate audio, video,networking and security.

We exercised Windows32 API [39] based threads thought JNI to utilize in Java. This research finding focuses on howJava can facilitate Win32 platform threads through JNI, which enables Java threads and native threads to schedule andexecute in hybrid mode. The Java Native Interface, or JNI, is a part of the Java language that allows the programmer toaccess functionality that was not written in Java. Because Java is a cross-platform language, the original intent was tomake it possible for Java programs to interact with the operating system. JNI also allows programmers to make use oflibraries written in C++. C++ code will eventually be compiled into a shared library that gets dynamically loaded intothe Java program. You need to load this library inside a Java static block so that it is loaded when the Java programbegins executing.

6. Conclusion

A Multi-core processor is typically a single processor which contains several cores on a chip. These multiple cores ona single chip combine to replicate the performance of a single faster processor. The individual cores on a multi-coreprocessor don’t necessarily run as fast as the highest performing single-core processors, but they improve overallperformance by handling more tasks in parallel. The performance boost can be seen by understanding the mannerin which single core and multi-core processors execute programs. Single core processors running multiple programswould assign time slice to work on one program and then assign different time slices for the remaining programs. If oneof the processes is taking longer time to complete then all the rest of the processes start lagging behind. However,In the case of multi-core processors if you have multiple tasks that can be run in parallel at the same time, each ofthem will be executed by a separate core in parallel thus boosting the performance.

Intel TBB is a C++ template library that provides tasks, parallel algorithms and containers to support for scalableparallel programming using standard C++ code. It enables us to specify logical parallelism instead of threads, targetsthreading for performance, compatible with other threading packages, emphasizes scalable, data parallel programmingand relies on generic programming. The essence of generic programming is writing the best possible algorithms withthe fewest constraints. The C++ Standard Template Library (STL) is a good example of generic programming in whichthe interfaces are specified by requirements on types. We implemented Intel TBB on Java through JNI, which canexploit painless usage of Intel TBB parallel algorithms that can be used in Java. In this research, we especially focusedon utilizing parallel−for algorithms, still there are opening to implement other algorithms too.

In a multiprocessor environment, the most important reason for using Pthreads is to take advantage of potentialparallelism. The primary motivation for using Pthreads is to realize potential program performance gains. Tasks can bescheduled to supersede or interrupt lower priority tasks. Tasks service events of indeterminate frequency and duration

© Elsevier Publications 2014. 673

Page 8: Overall Aspects of Java Native Threads onWin32 Platform

Bala Dhandayuthapani Veerasamy and G. M. Nasira

can be interleaved. The primary motivation for considering the use of Pthreads on SMP architecture is to achieveoptimum performance. In order for a program to take advantage of Pthreads, it must be able to be organized intodiscrete, independent tasks that can execute concurrently. Pthread-w32 is an abstraction of Win32 API for Pthreads.We implemented Pthreads using Pthread-w32 on Java through JNI, which can exploit to take advantages of Pthreadsin Java. Win32 API can be used in C, C++, Visual C++ or even in Java though JNA. Creating and managing threadscan be done in any programming languages, but taking the advantages of thread affinity scheduling can be possiblethough windows kernel. We implemented Win32 API on Java through JNI, which allows creating, managing andthread affinity scheduling in Java; As a result we got improved performance in completing program execution.

This research finding achieved the overview aspects on how Java can facilitate Win32, POSIX, TBB threads throughJNI, which enables Java threads, to add other threading library features in Java. In the same way, boost threads, C++threads, Intel Cilk Plus thread features can also implemented in Java. In this way, we can create a hybrid thread, whichtake advantages of dissimilar threading library features. Finally, we anticipate a common multithreading library, whichbe supposed to provide all features as one library.

References

[1] Cameron Hughes and Tracey Hughes, Professional Multicore Programming Design and Implementation for C++ Developers,Wiley Publishing, Inc., ISBN:978-0-470-28962-4, (2008).

[2] Clay Breshears, The Art of Concurrency, O’Reilly Media, Inc., ISBN: 978-0-596-52153-0, (2009).[3] Darryl Gove, Multicore Application Programming For Windows, Linux, and Oracle R©Solaris, Pearson Education, ISBN-10:

0-321-71137-8, (2011).[4] Joe Duffy, Concurrent Programming on Windows, Pearson Education Inc., United States of America, (2009).[5] Richard H. Carver and Kuo-chung tai, Modern Multithreading Implementing, Testing and Debugging Multithreaded Java and

C++/Pthreads/Win32 Programs, John Wiley & Sons, ISBN-13: 978-0-471-72504-6, (2006).[6] Shameem Akhter and Jason Roberts, Multi-Core Programming Increasing Performance Through Software Multi-threading,

Intel Corporation, ISBN 0-976483246.[7] Timothy G. Mattson, Beverly A. Sanders and Berna L. Massingill, Pattern Language for Parallel Programming,

Addision-Wesley, | ISBN-10: 0321228111, (2004).[8] Venkat Subramaniam, Programming Concurrency on the JVM, Pragmatic Programmers, LLC., ISBN-13:

978-1-934356-76-0, (2011).[9] API reference, http://docs.oracle.com/javase/7/docs/api/index.html

[10] Bil Lewis and Daniel J. Berg, Multithreaded Programming with JAVATMTechnology, Prentice Hall PTR, ISBN:0-13-017007-0, (1999).

[11] James Gosling, Bill Joy, Guy Steele, Gilad Bracha and Alex Buckley, The JavaTMLanguage Specification: Java SE 7 Edition,Oracle America Inc., (2011).

[12] Herbert schildt, JavaTM2: The Complete Reference, Fifth Edition, McGraw-Hill, ISBN: 0-07-222420-7, (2002).[13] Scott Oaks and Henry Wong, Java Threads, 2nd Edition, O’reilly, ISBN: 1-56592-418-5, (1999).[14] Fork/Join http://www.oracle.com/technetwork/articles/java/fork-join-422606.html.[15] ParallelArray, http://www.javac.info/jsr166z/index.html?jsr166z/forkjoin/ParallelArray.html.[16] Java Native Interface, http://java.sun.com/javase/6/docs/technotes/guides/jni/index.html.[17] Sheng Liang, The JavaTMNative Interface Programmer’s Guide and Specification, Sun Microsystems Inc., ISBN:

0-201-32577-2, (1999).[18] Get started with jna, https://jna.dev.java.net.[19] OpentMP, http://openmp.org/wp/.[20] Java OpenMP, https://www2.cs.fau.de/EN/research/JavaOpenMP/index.html.[21] The Message Passing Interface (MPI) standard, http://www.mcs.anl.gov/research/projects/mpi/.[22] MPI, http://www.open-mpi.org.[23] MPJ Express, http://mpj-express.org/.[24] Intel Threading Building Blocks [online] http://software.intel.com/en-us/intel-tbb/.[25] Intel Threading Building Blocks [online] http://threadingbuildingblocks.org.[26] Intel R©Threading Building Blocks (Intel R©TBB) User Guide [online] http://software.intel.com/en-us/node/467690.[27] Intel R©Threading Building Blocks Reference Manual [online] http://software.intel.com/en-us/node/467860.[28] James Reinders, Intel Threading Building Blocks Outfitting C++ for Multi-Core Processor Parallelism, O’Reilly Media,

United States of America, (2007).[29] Parallel Computing and Data Parallelism [online] http://www.codeproject.com/Articles/56035/Parallel-Computing-and-Data-

Parallelism (Accessed Feb 2010).[30] Bala Dhandayuthapani Veerasamy and Dr. G. M. Nasira, Java Native Intel Thread Building Blocks for Win32 Platform, Asian

Journal of Information Technology, Accepted for Publication, Medwell Publishing, ISSN: 682-3915 (Print), pp. 993–5994(Online).

[31] Bil Lewis and Daniel J. Berg, “PThreads Primer”, Sun Microsystems Inc., (1996).[32] Davud R. Butenhof, “Programming with POSIX Thread”, Addison Wesley Longman Inc., (1997).

674 © Elsevier Publications 2014.

Page 9: Overall Aspects of Java Native Threads onWin32 Platform

Overall Aspects of Java Native Threads on Win32 Platform

[33] Pthread-w32, https://sourceware.org/pthreads-win32/[34] Bala Dhandayuthapani Veerasamy and Dr. G. M. Nasira, Java Native Pthreads for Win32 Platform, “World Congress on

Computing and Communication Technologies (WCCCT’14), Feb. 27 2014-March 1 2014, Tiruchirappalli, published in IEEEXplore, pp. 195–199, ISBN: 978-1-4799-2876-7.

[35] Microsoft Developer Network (msdn): Setprocessaffinitymask, http://msdn.microsoft.com/library/default.asp?url=/library/enus/dllproc/base/ setprocessaffinitymask.asp.

[36] Bala Dhandayuthapani Veerasamy and Dr. G. M. Nasira, Setting CPU Affinity in Windows Based SMP Systems Using Java,International Journal of Scientific & Engineering Research, vol. 3, Issue 4, pp. 893–900, April (2012), Texas, USA, ISSN2229–5518.

[37] The Win32 Programming Tutorials for Fun (and Funny Too), http://www.installsetupconfig.com/win32programming/.[38] Windows Kernel Library (Win32), http://msdn.microsoft.com.[39] Bala Dhandayuthapani Veerasamy and Dr. G. M. Nasira, JNT - Java Native Thread for Win32 Platform, International Journal

of Computer Applications, vol. 70, Issue 24, pp. 1–9, May 2013, Foundation of Computer Science, New York, USA, ISSN0975–8887.

[40] Bala Dhandayuthapani Veerasamy and Dr. G. M. Nasira, Parallel: One Time Pad using Java, International Journal of Scientific& Engineering Research, vol. 3, Issue 11, pp. 1109–1117, November (2012), Texas, USA, ISSN 2229–5518.

© Elsevier Publications 2014. 675