Android—Why Dalvik?

  • Thread starter Lawrence D'Oliveiro
  • Start date
L

Lawrence D'Oliveiro

Understanding GNU autoconf is half the battle. It's written in a macro
language no one really understands, so half the code is copy-pasted.

I wouldn’t say that. I maintain one modest project that uses it
<https://github.com/ldo/dvdauthor>, and I’ve been able to make a bunch of
changes and improvements to its use of autoconf just from reading the
documentation.

And yes, I have made direct use of m4 in other projects.
Besides, all autoconf gets you is setting up the hundreds of #defines.
It does nothing else with respect to the #ifdef mess.

Still better than anything Java can offer.
 
L

Lawrence D'Oliveiro

[autoconf] doesn't exactly tend to work well for non-Linux operating
systems (such as Windows...).

It works just fine on a whole load of non-Linux operating systems, on a
whole range of hardware platforms. Among modern OSes, Windows is really the
only one left out.
 
L

Lawrence D'Oliveiro

The whole point of Java is that you are compiling to platform-neutral
bytecode, and running on a virtual machine.

Which is a lousy way of doing it.
The maintainer of the virtual machine has to worry about the OS- and
architecture-specific stuff. You don't.

In other words, Java code cannot be ported to a platform until the Java
system itself has been ported. And what is the Java system written in?
 
L

Lawrence D'Oliveiro

Andreas Leitgeb said:
I wouldn't exactly call "one size fits *almost* all" a failure.

It was never able to spread as widely as Sun originally hoped. And now we
see attempts to fix up its flaws (like the substitution of Dalvik for the
JVM in Android) raising the ire of Oracle, to the point where it wants to
sabotage them.
 
A

Andreas Leitgeb

Lawrence D'Oliveiro said:
Still better than anything Java can offer.

This is now about Java versus C, isn't it?
Java has one big advantage: The compiled thing is typically still
"portable". For this, it would "need" to do any OS-#ifdef'ery at
runtime, anyway, not at compile-time.
 
B

BGB

It was never able to spread as widely as Sun originally hoped. And now we
see attempts to fix up its flaws (like the substitution of Dalvik for the
JVM in Android) raising the ire of Oracle, to the point where it wants to
sabotage them.

yeah... Sun wanted world domination...

they didn't get this, but they still managed to do pretty good (putting
Java on par with C and C++ in terms of popularity).

of course, C# is currently up there as well, so it is mostly a battle
between C, C++, Java, and C# for the title of "most widely used
language...".
 
L

Lawrence D'Oliveiro

Andreas Leitgeb said:
This is now about Java versus C, isn't it?
Java has one big advantage: The compiled thing is typically still
"portable". For this, it would "need" to do any OS-#ifdef'ery at
runtime, anyway, not at compile-time.

But isn’t Java supposed to be “statically†typed?
 
L

Lawrence D'Oliveiro

C/C++. If I'm not mistaken. :)

You make a valid point. On the other hand, unless I'm doing something
rather esoteric or I need access to hardware (e.g. USB ports), the Java
"write once, run just about anywhere" model works quite well for me.

Piggybacking on top of the C/C++ system, which is self-hosting and self-
porting.

“Write once, run everywhere†is more true of C than it is of Java; a
portable compiler like GCC means C is the most portable language in the
world.
 
A

Andreas Leitgeb

Steve Sobol said:
C/C++. If I'm not mistaken. :)

The question is not, what the JVM is written in, but *who* does the porting
work to a particular new platform.

If you've just designed a new microprocessor and need to get a specific
program to run on it, then chances are high, that porting a small C-program
to the new platform's peculiarities will be easier, than to port the whole
JVM to it (and have the program written in Java). Oh, and you'd probably
need a C-compiler ported to it anyway, so I wasn't mentioning it for the
comparison.

If, on the other hand, all of the interesting platforms already have a
Java on it (ported by someone else) then doing the program in Java could
well be the better choice.

My impression is, that Android typically runs on hw-platforms
- with a relatively small screen (both: physically and pixels) and no
normal keyboard. (Even though you could pair it with a bluetooth
keyboard, you wouldn't have one with you, most of the time.)
- with a multi-touch-sensitive touch-screen, that can deal with
two (or more) fingers touching it at the same time and with
varying pressure.
- which don't know the concept of "hovering" above a gadget (for
tooltips) or alternative-button clicks (for context menus)

Whereas Java (J2SE) would typically run on hw-platforms that would be
characterized by logically inverting each of the items above.

Any *GUI* app, that might conceivably run on both types of platforms, would
either be really two-separate-apps-in-one, or suck terribly on at least one
of these platforms.
 
B

BGB

This is now about Java versus C, isn't it?
Java has one big advantage: The compiled thing is typically still
"portable". For this, it would "need" to do any OS-#ifdef'ery at
runtime, anyway, not at compile-time.

note:
it could be done at JIT-time, which is not strictly the same as
run-time, since JIT-time operations need not involve runtime checks...

however, yes, 'javac' in such a case would likely spit out code with
every possible ifdef branch included, and then the classloader/JIT would
discard any of the branches which are irrelevant to the given target.


how this would "best" be done in a standard JVM is uncertain, but my VM
(technically, not a JVM) basically handles it via block-folding and
attributes (ifdef blocks are folded off into their own
functions/methods, which are invisibly called by the parent method, with
any dropped blocks having no-op calls).


or such...
 
A

Andreas Leitgeb

Lawrence D'Oliveiro said:
But isn’t Java supposed to be “statically†typed?

I'd guess it is, but fail to see what you're up to.
What about Dalvik in this context? Is it?
 
B

BGB

The question is not, what the JVM is written in, but *who* does the porting
work to a particular new platform.

If you've just designed a new microprocessor and need to get a specific
program to run on it, then chances are high, that porting a small C-program
to the new platform's peculiarities will be easier, than to port the whole
JVM to it (and have the program written in Java). Oh, and you'd probably
need a C-compiler ported to it anyway, so I wasn't mentioning it for the
comparison.

well, the C compiler need not be necessarily ported to it, since very
often with such small embedded systems, one cross-compiles to them. then
one just needs a C compiler which targets the given CPU architecture in
use, which may well be a bit easier than getting something more big and
complex (such as a VM framework) ported to it.

If, on the other hand, all of the interesting platforms already have a
Java on it (ported by someone else) then doing the program in Java could
well be the better choice.

it depends a lot on the type of app though, such as how effectively, or
portably, the thing that needs to be done can be implemented purely or
mostly in Java.

for example, Minecraft was written primarily in Java, but still depends
somewhat on special-purpose native interfaces (such as LWJGL) to expose
more OS-level functionality (OpenGL, sound, lower-level keyboard/mouse
input, ...).


about at the time JNI starts really coming into the picture, then things
start looking a little less pretty.

mapping DirectX to Java would also be a bit problematic.


but, yeah, for a vanilla GUI app, Java makes a good deal of sense (well,
along with C#, but C# is mostly only really ideal for very quick/dirty
GUI apps where one doesn't care so much about non-Windows targets).


My impression is, that Android typically runs on hw-platforms
- with a relatively small screen (both: physically and pixels) and no
normal keyboard. (Even though you could pair it with a bluetooth
keyboard, you wouldn't have one with you, most of the time.)
- with a multi-touch-sensitive touch-screen, that can deal with
two (or more) fingers touching it at the same time and with
varying pressure.
- which don't know the concept of "hovering" above a gadget (for
tooltips) or alternative-button clicks (for context menus)

Whereas Java (J2SE) would typically run on hw-platforms that would be
characterized by logically inverting each of the items above.

Any *GUI* app, that might conceivably run on both types of platforms, would
either be really two-separate-apps-in-one, or suck terribly on at least one
of these platforms.

"wut?... so you are saying I can't reasonably use 3DS Max on a cell phone?".


but, yeah, fair enough.

it does pose a bit of a UI design problem, as UIs which are well suited
to a desktop PC are not necessarily as well suited to smaller screens or
keyboards (sometimes even laptops, for example if the app has lots of
on-screen items/information/... and/or makes heavy use of keyboard
shortcuts).

whereas UI designs which work well on cellphones (such as the usual NxN
tiled icons, ...) would look silly on a laptop or desktop (either the
buttons are comically huge, or one has a giant scrolling desktop,
neither of which makes all that much sense).


so, yeah, probably difference sorts of UI designs are needed...

as to whether or not this would be a case of "two apps in one" would
likely depend more on the nature of the app, and possibly how central
the UI design is to its operation.


or such...
 
N

Nasser M. Abbasi

Looks like Java is in long-term decline, and will be surpassed by C soon
<http://www.tiobe.com/index.php/content/paperinfo/tpci/index.html>. Even C++
and Perl are falling off, and Visual Basic might be too.

What’s showing long-term growth? C# and Python.

Hello Lawrence;

I tried to find if one can run Python inside a browser, like
one can do with Java, but could not find a way. Looked at
all the Phyton sites and wiki, etc...

Do you know of a way, or if this might be something in the works
for the future of Python?

Witout the ability to run Python directly inside the browser
(in a VM like env.), then I do not see how Python can be
considered a viable solution for the new rich internet
applications computing world we are supposed to be moving to,
where Javascript and HTML5 are the prefered
tools of development since they are browser friendly/native
things.

At least, Java can run inside the browser since it has a
VM, but Python can't, at least not today? or Am I wrong
on this?

--Nasser
 
L

Lawrence D'Oliveiro

Witout the ability to run Python directly inside the browser
(in a VM like env.), then I do not see how Python can be
considered a viable solution for the new rich internet
applications computing world we are supposed to be moving to,
where Javascript and HTML5 are the prefered
tools of development since they are browser friendly/native
things.

JavaScript is the language of choice for that.
At least, Java can run inside the browser since it has a
VM ...

Which you have to download and install separately, and most people can’t be
bothered with that.
 
L

Lawrence D'Oliveiro

but, my experience is mostly with Windows, where autoconf/configure
tends not to even work much of the time with "blessed" environments,
such as Cygwin and MinGW.

Free Software in general seems to be troublesome on Windows.
also, it is another problem if one tends to use MSVC and needs to build
with MSVC to use the library in a project compiled with MSVC ...

Using MSVC brings its own share of problems. I remember on the Python group,
if you wanted to build a C/C++ extension for Python, you had to compile it
with the exact same version of MSVC as was used for that version of Python,
otherwise it wouldn’t work.

Windows as a whole just doesn’t seem to be set up for collaborative software
development.
 
N

Nasser M. Abbasi

Which you have to download and install separately, and most people can’t be
bothered with that.

Do you have an insight why Java JRE is not shipped with
the browser itself?

Why can't say oracle, when they have a new Java VM ready, send
it to all those interested in integrating it in their browsers
build system (firefox, apple, Microsoft, google chrome, etc..)
and then those will work with Oracle to integrate the JRE
into the browser build if they wish.

I never understood why does the browser ships without java,
then one has to go download the JRE separately. Why not have
that part of the browser installation itself?

Why can't say Firefox comes Java ready?

The browser size will be a little larger, but so what? internet
speed is fast these days, who cares if it is 18 MB larger now.

Why do you think this is not done? It due to some legal issues?
or technical ones?

thanks
--Nasser
 
J

Joshua Cranmer

Using MSVC brings its own share of problems. I remember on the Python group,
if you wanted to build a C/C++ extension for Python, you had to compile it
with the exact same version of MSVC as was used for that version of Python,
otherwise it wouldn’t work.

Funny. I thought C/C++ was supposed to be portable. With Java, it
doesn't matter which compiler I use to link the binary, they all the do
same thing. Even if I don't program my code in Java. ;-)

Java has extreme ABI portability--any compiler, any OS, any arch. C is
somewhat portable (between compilers on the same OS and arch), and C++
isn't very portable between compilers, particularly MSVC/gcc 3.x/gcc 4.x.
 
J

Joshua Cranmer

Do you have an insight why Java JRE is not shipped with
the browser itself?

License issues is the biggest one. There is also the fact that it
defeats the purpose of the plugin architecture: it's not like Firefox
bundles Flash, the other You Need This plugin.

Actually, as an aside, Firefox used to have a deep integration via OJI,
and until Firefox 3 or so, it was theoretically possible to write your
extension in Java (JavaXPCOM has since been broken, I think). Nowadays,
Mozilla-Java integration is mostly limited to the standard NPAPI (i.e.,
plugin) architecture capabilities.
The browser size will be a little larger, but so what? internet
speed is fast these days, who cares if it is 18 MB larger now.

Judging from wget, the size of Firefox right now is 12 MB. While
download size is not a huge priority, a 150% regression is definitely
not going to be accepted. And keep in mind that not everyone has access
to high-speed internet; e.g., Africa.
 
B

BGB

Funny. I thought C/C++ was supposed to be portable. With Java, it
doesn't matter which compiler I use to link the binary, they all the do
same thing. Even if I don't program my code in Java. ;-)

Java has extreme ABI portability--any compiler, any OS, any arch. C is
somewhat portable (between compilers on the same OS and arch), and C++
isn't very portable between compilers, particularly MSVC/gcc 3.x/gcc 4.x.

yeah... sadly, the C ABI is a little bit prone to variations, I suspect
often because compiler/ABI implementers are prone to try to
micro-optimize things at the ABI level, leading to fussy special cases,
and cases where the compilers often vary.


for example, in the usual x86 C ABI:
values are generally passed on the stack;
structs are generally done by passing the return-value address to the
called function;
....

some compilers, in their wisdom, in certain cases, try to pass arguments
in registers, or try to return the struct in registers, ...

then compiler A and B break because A expected the return value to be
via a memory copy and B expected it via registers, ...

and, certain ABIs, such as the AMD64 ABI, are just plain complicated...
(I personally like the design of the Win64 x64 ABI better, as it is much
simpler...).


then with C++, there is a somewhat different problem:
nearly every compiler has its own ABI (or subtle variations on an
existing ABI), and in the GCC 3/4 case, because they changed the C++ ABI
between compiler versions.


sadly though sometimes, the linker just blowing up in ones face is
actually often the better case.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top