VMs and Dalvik VM

I have been thinking to write a blog on something, So I thought now to write about Virtual Machine. Which I have learned DALVIK VM in Linux For You magazine last month and almost all content are copied from that article only  J.

Let me start with What is VM?

Linux For You magazine says,

Virtual Machine is an isolated, self-contained implementation that abstracts hardware resources. Typically, it simulates an actual physical machine capable of executing instructions sets. Broadly VM are classified into two types,

  1. Process VMs
  2. System VMs

Process VMs:

A process VM, sometimes called an application virtual machine, runs as a normal application inside a host OS and supports a single process. It is created when that process is started and destroyed when it exits. Its purpose is to provide a platform-independent programming environment that abstracts away details of the underlying hardware or operating system, and allows a program to execute in the same way on any platform.

This type of VM has become popular with the Java programming language, which is implemented using the Java virtual machine. Other examples include the Parrot virtual machine, which serves as an abstraction layer for several interpreted languages, and the .NET Framework, which runs on a VM called the Common Language Runtime.

System VMs:

Supports the execution of a complete operating system (eg: VirtualBox, VMWare).

System virtual machines (sometimes called hardware virtual machines) allow the sharing of the underlying physical machine resources between different virtual machines, each running its own operating system. The software layer providing the virtualization is called a virtual machine monitor or hypervisor. A hypervisor can run on bare hardware (Type 1 or native VM) or on top of an operating system (Type 2 or hosted VM).

I have learned little bit on system VMs while in my college with helps of my Guru (Ewards). Where with help of System VMs you can run XP in linux, tats wat I tried in my laptop.

In this article, will see on Process based VMs.

For example, Java applets run in a Java virtual machine (VM) that has no access to the host operating system. This design has two advantages:

System Independence: A Java application will run the same in any Java VM, regardless of the hardware and software underlying the system.

Security: Because the VM has no contact with the operating system, there is little possibility of a Java program damaging other files or applications.

The second advantage, however, has a downside. Because programs running in a VM are separate from the operating system, they cannot take advantage of special operating system features.

VM implementations:

VM are implemented in two ways,

  1. Register based VMs
  2. Stack based VMs

Register based VMs:

It computation model assumes register as the memory, and operands are accesed with explicit address coded in an instruction.

Stack based VMs:

Memory takes the form of a LIFO stack. Every operation boils down into PUSH/POP or STORE/LOAD. These instructions do not need explicit operand address, because the operand is always available with stack pointer. Ex:- Microsoft .NET and Sun JVM.

Traditionally,

People preferred to stack-based rather than register-base VMs, main reason of this choice was the simplicity of the complier. And stack-based instruction are shorter of (PUSH/POP). But register-based instructions are quadruple. Even though advantages of stack-based is diminishes in terms of number of instruction, which some of stack-based instructions need to express the register-based instructions.

Example: “a = b + c” would need stack VM:

LOAD  C
LOAD  B
ADD
STORE A

Register VM:

“add a,b,c”

Comparison:

Stack VMs, operands are accessed relative to the stack pointer, but in register VMs need to preovide the location of all operands. Having all the operands in instruction has it benefits of execution faster compared to stack VM.

Stack VM consume more memory cycle and temp values often stored in main memory. Register VMs, temp values usually remain inregister.

Stack VMs are unable to use few optimisation, in-case of expression, which recalculated each time they appear in the code. Register VM can calculate an expression once, and keep that in  a register for all future references.

So Dalvik VM preferred register based VM, and thou google choose to implement it in andriod.

Dalvik VM :

Introduction:

In stead of using usual JVM, Google have implemented their own VM of “Dalvik VM”

The Dalvik virtual machine is a register-based virtual machine, designed and written by Dan Bornstein with contributions from other Google engineers as part of the Android mobile phone platform.

It is optimized for low memory requirements, and is designed to allow multiple VM instances to run at once, relying on the underlying operating system for process isolation, memory management and threading support. Dalvik is often referred to as a Java Virtual Machine, but this is not strictly accurate, as the bytecode on which it operates is not Java bytecode.

License and patent:

Dalvik is claimed by Google to be a clean-room implementation rather than a development on top of a standard Java runtime, which would mean it might not inherit copyright-based license restrictions from either the standard-edition or open-source-edition Java runtimes.

Dalvik is published under the terms of the Apache License 2.0.

On 12 August 2010, Oracle, which acquired Sun Microsystems in April 2009 and therefore owns the rights to Java, sued Google over claimed infringement of copyrights and patents. In developing Android, it is alleged that Google knowingly, directly and repeatedly infringed Oracle’s Java-related intellectual property.

Specifically the patent infringement claim references seven patents including US Patent No. 5966702 “Method And Apparatus For Preprocessing And Packaging Class Files”, and US Patent No. 6910205 “Interpreting Functions Utilizing A Hybrid Of Virtual And Native Machine Instructions”. It also references US Patent No. RE38104 “Method And Apparatus For Resolving Data References In Generated Code”.

The Dex File Format:

In standard Java environments, Java source code is compiled into Java bytecode, which is stored within .class files. The .class files are read by the JVM at runtime. Each class in your Java code will result in one .class file. This means that if you have, say, one .java source file that contains one public class, one static inner class, and three anonymous classes, the compilation process (javac) will output 5 .class files.

On the Android platform, Java source code is still compiled into .class files. But after .class files are generated, the “dx” tool is used to convert the .class files into a .dex, or Dalvik Executable, file. Whereas a .class file contains only one class, a .dex file contains multiple classes. It is the .dex file that is executed on the Dalvik VM.

 

Reference:

  1. Linux For you article.
  2. http://www.dalvikvm.com
  3. Wiki
  4. Ofcourse www.google.com

Geolocation using JavaScript

I have been thinking to buy a mobile which has GPS support. But what a petty now even my laptop supports or helps to find my Geolocation through JavaScript and my browser. Have wondered how !!! Ya me too had same. In this blog will details about how can we work thro’ and its features.

Geolocation Specification:

Actually, W3C have been released API specification of Geolocation from 2008 onwards. And now it become implemented by all the browser. Started from firefox, chrome and now IE9 also supports Geolocation.

The Geolocation API defines a high-level interface to location information associated only with the device hosting the implementation, such as latitude and longitude. The API itself is agnostic of the underlying location information sources. Common sources of location information include Global Positioning System (GPS) and location inferred from network signals such as IP address, RFID, WiFi and Bluetooth MAC addresses, and GSM/CDMA cell IDs, as well as user input. No guarantee is given that the API returns the device’s actual location.[W3C – Definition]

How to use in your page:

You can get the Geolocation object from

navigator.geolocation

For best pratice, check if the geolocation object is null, then the browser doesn’t supports Geolocation.

 

navigator.geolocation.getCurrentPosition(getPositionFunction);

getPositionFunction(position){

latitude = position.coords.latitude;

longitude=position.coords.longitude;

}

Features:

  • Requesting repeated position, helps to update the location automatically.
  • Requesting from cached position

Privacy:

Due to privacy issues of retrieving the users location,

W3C has requested a privacy considerations for implementors of Geolocation API (i.e browsers) that, User Agents must not send location Information to Web Sites without permission of user.

So browser have implemented in such a way, Browsers will popup a dialog bar at top, where we can either “allow” or “deny” the service to send to the web site.

Privacy considerations for receipients (i.e. Web Sites which use navigator API),  If the Geolocation information is stored, then it should be allowed to update or delete to user.

Implementation and more properties:

This implementation is for those who gonna implement there own geolocation algorithm,

There are two main Interfaces NavigatorGeolocation and Geolocation.

Geolocation interfaces has signature for all the methods.

Position interface a property.

Coordinates – which holds all the location information. Properties in Coordinates are

  1. latitude
  2. longitude
  3. altitude – height of the position in meters, if implementor cannot provide will be NULL.
  4. accuracy – accuracy level of location in meters.
  5. altitudeAccuracy – both the accuracy should be 95% confidence level.
  6. heading – denotes the direction of travel in degrees,
  7. speed – denotes current ground speed, in m/s.

Usage:

Most of the commerical sites are started using in their sites.

  • Mostly on Maps, to show up our current position.
  • Apple trailers – get your current position and display the movies shows in your city.

So use the HTML5 – Geolocation and provide better RIA to your clients.

But then when I’m tried to get the location thro’ some test sites, It have been shows current city, location is nearly 20 Kms around.

Smile with tongue out

— The above information are taken from W3C specifications.

Map Reduce !

Google Map Reduce :

MapReduce is a framework for processing huge datasets on certain kinds of distributable problems using a large number of computers (nodes), collectively referred to as a cluster. Computational processing can occur on data stored either in a filesystem (unstructured) or within a database(structured).

"Map" step: The master node takes the input, chops it up into smaller sub-problems, and distributes those to worker nodes. A worker node may do this again in turn, leading to a multi-level tree structure.

The worker node processes that smaller problem, and passes the answer back to its master node.

"Reduce" step: The master node then takes the answers to all the sub-problems and combines them in a way to get the output – the answer to the problem it was originally trying to solve.

Parallel Computing :

To learn why we are moving from serial to paraller computing. And how Map Reduce works on parallel computing concepts. Refer the following link which show from basic

http://code.google.com/edu/parallel/mapreduce-tutorial.html

Those Who need to learn from basic where as a wonder full tutorial, So nice and step-by-step from Google Developer (Aaron ) – an awesome guy. This tutorial is about Distributed Computing, Map Reduce and Cloud Computing.

http://www.youtube.com/watch?v=yjPBkvYh-ss

This link is first part and it contains 5 part. You should watch all the 5 and atlast you will be have an idea how distributed computing works.

An Awesome Video where I have seen, when I’m studing college, And impressed on Hadoop.

Oops !. Let me intro about what is Hadoop.

Hadoop !

Apache Hadoop is a Java software framework that supports data-intensive distributed applications under a free license.[1] It enables applications to work with thousands of nodes and petabytes of data. Hadoop was inspired by Google‘s MapReduceand Google File System (GFS) papers.

Now Hadoop is used by all over world for Distributed and Cloud Computing from Institute to Yahoo, MicroSoft.

To learn on Hadoop, refer the following link

http://hadoop.apache.org/

To get tutorial links, examples look in to

http://wiki.apache.org/hadoop/

Yahoo is the major supportive for Hadoop,

http://developer.yahoo.com/hadoop/tutorial/

Cloudera

Cloudera provides better support of platform to work on Hadoop.

http://www.cloudera.com/

They offer a VMWare to work on Hadoop and lot more.

Got your stomach full !. Its just a starting, lot more there.

Hive :

Hive is a data warehouse infrastructure built on top of Hadoop that provides tools to enable easy data summarization, adhoc querying and analysis of large datasets data stored in Hadoop files.

Just start to learn and start your own cluster today.

Ubuntu has good support to work on Hadoop.

http://www.michael-noll.com/wiki/Running_Hadoop_On_Ubuntu_Linux_(Single-Node_Cluster)

And still do you think why do I need to go forward.

Ok Lets check Who Are using Hadoop.

Adobe, AOL, FaceBook, PSG Tech, Google, IBM, IIT, Yahoo and this list goes on…..

If you wanna really to learn the Cutting Edge Technology, You are already delayed back.

Lets Start learning it from Today onwards and rock in with Distributive and Cloud Computing.

JavaScript Minifier

AJAX Minifier

Microsoft AJAX Minifier 4.0 have been released and do you wonder what is about ..?

The Microsoft Ajax Minifier enables you to improve the performance of your Ajax applications by reducing the size of your JavaScript files. The Microsoft Ajax Minifier supports two levels of minification: normal crunching and hypercrunching. Normal crunching refers to the process of removing unnecessary whitespace, comments, semicolons, and curly braces. Hypercrunching refers to the process of shortening the names of local variables and removing unreachable code.

The Microsoft Ajax Minifier includes the following components:

  • Command-line tool– ajaxmin.exe — Enables you to minify JavaScript files from a command prompt.
  • MSBuild Task — ajaxmintask.dll — Enables you to minify JavaScript files in a Visual Studio project automatically when performing a build.
  • Component — ajaxmin.dll — Enables you to to use the Microsoft Ajax Minifier programmatically.

Here is the link where you can download the AJAX Minifier:

http://aspnet.codeplex.com/releases/view/34488

And here is the tutorial link where it was explained little brief on it.

http://www.ajaxprojects.com/ajax/tutorialdetails.php?itemid=766

Yesterday I found hard to implement minifier support through my C#, Because I couldn’t get any tutorial anywhere, And at last I found a tutorial page.

http://www.asp.net/ajaxlibrary/AjaxMinDLL.ashx

There are so many other Minifiers on existing

JSMin

– one of the famous tools to minify the Javascript

http://www.crockford.com/javascript/jsmin.html

Shrinksafe

— A Dojo’s toolkit

http://o.dojotoolkit.org/docs/shrinksafe

Packer

–  Dean Edwards

http://base2.googlecode.com/svn/trunk/src/apps/packer/packer.html

JSO

— JS-Optimizer

http://js-optimizer.sourceforge.net/

JAWR

— A tool for java web application

https://jawr.dev.java.net/

An online tool — http://jscompress.com/

YUI

— Yahoo’s most performance and light weight compresser

http://developer.yahoo.com/yui/compressor/

At last by using the Minifiers, Make you application light weight, hight performance and load quicker than others.

Chrome eXtension!

I have been learning and watch about chrome extensions, Where as I thought it may be something difficult. I got the result of even a  Mid-School student can write their own chrome extensions.

Let me start with what is "Chrome Extension". Chrome Extensions are like tiny add-ons where it gives a way to customize your chrome browser.

In this blog I will explain how to create a "Hello World" extension — where we used to hear this first session of the college.

Chrome Extension is just a combined package which contains just a web page. Those who are well and good in web apps., can easily write there own extension.

Manifest.JSON:

Manifest.JSON is the manifest file which contain the configurations like icon, popup page etc…

Here is the manifest.json file of Hello World extension.

manifest.json

Name: Name of the extension

Version: Current version of the extension, which helps to update from the browser.

Default_icon : Will be display in the tool bar.

popup : Its just a html page, will be displayed when click on the "default_icon".

popup.html

popup.html

Creating these two files, store it under a folder with the "default_icon" which here we specified as "icon.png".

We are almost finished with the code part.

What’s next ? Need to load the extension to your browser.

  1. Go to Tools menu -> extensions.
  2. Click on "Develop mode" which you will find in right side.
  3. Click "load unpackaged extension" and select the folder which you saved the files

Thats it ! The extension was ready. And you will find the icon being displayed on right side of the address bar. Click on it and you will find the hello world extension works Cooooool.

helloworld extension

Wow ! We have created a hello world extension.

Isn’t it easy to write your own extension, Then what you waiting for start writing your own extension’s which you feel to have in your browser and make it publish so that other also will get benefit of it.

Here is a nice video, where I have learned :

Here are some link which helps to learn more about chrome extensions.

http://code.google.com/chrome/extensions/getstarted.html

http://blog.chromium.org/