Java and Linux
Hi: I'm new in Linux. Please forgive me if the questions are too simple. Q1: What version of Java (1.1 or 1.2) does JVM inside Blackdown JDK package support? Q2: A Java application was developed on Windows NT 4.0 (Intel) by using VisualCafe 3.0. Can we simply move all class files of the application to Redhat 6.0 Linux (Intel), and use JVM inside Blackdown to run it without any modification? Thank you in advance. Lee -- To UNSUBSCRIBE, email to [EMAIL PROTECTED] with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]
Can we run Java app from a CD with Blackdown?
Hi: We got a few questions on deployment with Blackdown. It would be appreciated if someone could help. Q1: After we finish a Java application development on Windows NT 4.0 (Intel) with VisualCafe 3.0, is it possible to include everything** on a CD, and let user run the Java application from the CD on Redhat 6.0 Linux (Intel) without any installation or file copy? ** "everything" includes: - all class files or a JAR file of the Java application - supporting files from VisualCafe 3.0 (they are said 100% pure) - Blackdown JVM and supporting files - what else? Q2: Can we use Blackdown in this way (i.e. from a CD without installation), or we have to install it first? Q3: If we can use it without a installation, then which Blackdown files should be included on the CD, and any special file structure? Q4: Does Blackdown JVM generate any temporary files during running? We plan to use a CD-ROM not CD-RW, so can't add any temp files to the CD. Q5: Is there any JRE for Linux like the one for NT? We are not familiar with Blackdown or Linux yet :( so please give detail information if possible. Thank you in advance. Lee -- To UNSUBSCRIBE, email to [EMAIL PROTECTED] with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]
BlackDown Files for Redhat Linux 6.1
Hi, Could you please tell me what files we should download from Blackdown for Redhat Linux 6.1? Thanks. L. -- To UNSUBSCRIBE, email to [EMAIL PROTECTED] with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]
Kaffe in RedHat Linux 6.1
Hi: Is anybody using Java compiler and run time for Linux coming with RedHat Linux 6.1? The package name is "kaffe" and is on RedHat 6.1 first CD. I can compile and run java applications with them. Can someone tell me something about it compare with Blackdown and IBM's Java for Linux? Thanks. Lee -- To UNSUBSCRIBE, email to [EMAIL PROTECTED] with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]
Is it another option for Java-Linux (Kaffe in RedHat Linux 6.1)?
Hi: Is anybody using Java compiler and run time for Linux coming with RedHat Linux 6.1? The package name is "kaffe" and is on RedHat 6.1 first CD. I can compile and run java applications with them. Can someone tell me something about it compare with Blackdown and IBM's Java for Linux? Thanks. Lee -- To UNSUBSCRIBE, email to [EMAIL PROTECTED] with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]
Compile Error from BlackDown jdk 1.1.7
Hi: I installed BlackDown jdk_1.1.7-v3-glibc-x86.tar.gz on RedHat 6.1 Linux. There is no problem to compile a simple java application (hello.java). But got compile error when compile an application with Swing component. The error message is "Package com.sun.java.swing.* not found in import". What I missed? Should I download and install JFC/Swing package separately? Thank you. Lee -- To UNSUBSCRIBE, email to [EMAIL PROTECTED] with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]
RE: Thread in the Linux's JVM
This sounds to me like Java and C/C++ native code can talk to each other only if they (java and native code) are in the same thread. Is it right, or in the same process? Suppose C/C++ native code creates another thread within the shared lib, can the newly-created thread interact with (call back to) java code? The newly-created thread should be in the same process as its parent thread and java code, right? Thank you. Lee -Original Message- From: Nathan Meyers [mailto:[EMAIL PROTECTED]] Sent: Tuesday, November 09, 1999 11:52 AM To: [EMAIL PROTECTED] Cc: Evandro Luquini; [EMAIL PROTECTED] Subject: Re: Thread in the Linux's JVM Jacob Nikom wrote: > > So, you think that JNI does not represent any specific issues in > Java multithreading? Does the JNI/C code executes in the same thread > as the Java method which invoked it? JNI code is just the native "back end" of certain Java methods. It runs in whatever thread the caller is running in. The only specific issue I know of is that it's probably easier to hog the CPU in native code than in Java code. > Also, what about event-dispatching thread? In the documentation about > InvokeLater() method there is no any mention that you have to change > the non-event-dispatching thread's priority in order to allow the > event-dispatching thread get called. Is it simply assumed? This is > strange. This isn't about thread priorities. In a non-preemptive threading environment, if one thread is hogging the CPU and never yielding, the other threads will not get to run regardless of priority. InvokeLater schedules some code to be run in a different thread (the event dispatching thread), but doesn't guarantee that that thread will get any time. You still have to avoid hogging the CPU in all threads. Nathan > > Jacob Nikom > > Nathan Meyers wrote: > > > > Jacob Nikom wrote: > > > > > It would be nice to know more about multithreading features of Linux > > > JVM. > > > > There are two threading models. If you run with green threads, there is > > no preemption, and control passes between threads either with yield() > > calls or possibly with other calls that can block (such as sleep() and > > various I/O calls). > > > > If you run with native threads, the JVM is using the system's pthread > > API, which (except for very strangely configured systems) means it's > > using kernel threads. They give you preemption but not thread > > priorities, and there is no guarantee about the size of the time slices, > > when preemption occurs, or how thread execution is distributed across > > multiple processors. > > > > It sounds from your description like you're relying on preemption. > > Unfortunately, that's a bad thing - Java doesn't guarantee that you'll > > get it, and you need to code as if preemption will not happen. > > SwingWorker is a nice tool for conveniently launching another thread, > > but it doesn't magically turn non-preemptive threads into preemptive > > threads. > > > > So to your problem... why did the behavior change when you rewrote some > > of your Java methods as native methods? My guess is that you were using > > some Java methods that do voluntary yields, and you stopped using them > > when you rewrote the code as native methods. > > > > BTW, that Sun article mentioned in Evandro's original mail (below) > > discusses why Solaris is a good platform for applications that rely on > > preemptive multi-threading. But it's a Solaris marketing article, not a > > Java programming guide. The Java portability message is very clear: > > don't rely on preemption. > > > > Nathan > > > > > > > > Hi, > > > > > > Thank you for bringing up this question. I also have problems with > > > multiple threads in Linux. In my case the behavior of threads with > > > JNI is different from pure Java behavior. > > > > > > I use SwingWorker class. If I don't have JNI methods I don't have > > > to use yield() method. If I replace my Java methods with JNI calls > > > I must use yield(), otherwise the application simply does not work. > > > There is no mentioning of yield() method in any SwingWorker-related > > > documentation. > > > > > > It would be nice to know more about multithreading features of Linux > > > JVM. > > > > > > Jacob Nikom > > > > > > > Evandro Luquini wrote: > > > > > > > > Hi, > > > > In the JavaWord article called "programming Java threads in the real > > > > world, Part 1( > > > > http://www.javaworld.com/jw-09-1998/jw-09-threads.html)", the author > > > > sad that "Java's promise of platform independence falls flat on its > > > > face in the threads arena". If you read this paper you will can see > > > > two plataform example : NT and Solaris. > > > > > > > > Major question is what scheduling is implemented by the Linux JVM and > > > > the Linux OS. Does it use a nonpreemptive our preemptive scheduler ? > > > > > > > > The other important question is about what thread's architecture is > > > > implement by Linux O.S. I am asking it because in the sun's
RE: Thread in the Linux's JVM
-Original Message-
From: Nathan Meyers [mailto:[EMAIL PROTECTED]]
Sent: Thursday, November 18, 1999 3:32 PM
To: [EMAIL PROTECTED]
Cc: [EMAIL PROTECTED]
Subject: Re: Thread in the Linux's JVM
On Thu, Nov 18, 1999 at 11:59:04AM -0600, [EMAIL PROTECTED] wrote:
> This sounds to me like Java and C/C++ native code can talk to each other
> only if they (java and native code) are in the same thread. Is it right,
or
> in the same process?
What do you mean "talk to each other"?
[Lee]
{
By "talking to each other", I meant that java calls native method;
and native code calls back to java.
}
The JVM is a multi-threaded native application. Most of the time it's
running native code that implements an interpreter, but some of the time
it's running native code that doesn't happen to be in the interpreter
(such as JNI methods or JIT-compiled code). Nothing magic (thread-wise)
happens when it moves between the interpreter and other native code -
no new thread is created - it just happens to be running code outside of
the interpreter. The interpreter jumps to compiled code when it runs
a JNI method, and compiled code can call interpreted code through some
of the functions in the JNINativeInterface structure.
So maybe you can clarify the term "talk to each other"? When method foo()
calls method bar(), is foo() "talking to" bar()? Method bar() isn't even
running until foo() calls it... once that happens, yes, bar() is running in
the same thread (regardless of language).
[Lee]
{
This is a great comment! I didn't pay attention to the
simple but important fact - "The JVM is a multi-threaded
native application". Can we say that when java calls a native
method, what really happens is JVM, the native application,
loads a shared lib into its (JVM's) memory space and invokes
one of the shared lib's methods. Therefore, no new thread is
created at the time when java calls a native method. Is it
right or I miss something again here?
If it's true, then why you say "When Java creates a native
thread" below? Is a new thread really created when java calls
a native method, and how?
}
> Suppose C/C++ native code creates another thread within the shared lib,
can
> the newly-created thread interact with (call back to) java code? The
> newly-created thread should be in the same process as its parent thread
and
> java code, right?
When Java creates a native thread, it also creates additional information
for use by the JVM. If your own native code creates a thread, it needs
to "attach" it to the JVM so the JVM knows about it. You'll find some
discussion and sample code at:
http://developer.java.sun.com/developer/onlineTraining/Programming/JDCBook/j
niref.html
[Lee]
{
Yes. Thanks.
}
The important thing is that both the JVM and your native code use the
same threading mechanism. Since you're using pthread_create() to create
threads, you need to run a version of the JVM (native) that uses the
same system. AFAIK, there's no way for JNI code to create new threads
in a green thread environment.
[Lee]
{
They uses the same threading mechanism or the same thread?
}
At any rate, all threads (native or green) are running "in the same
process". With native threads, however, different threads have their
own PIDs and entries in the process table, which results in confusing
"ps" results. (Which is why I put "in the same process" in quotes - if
you define a "process" as something with its own PID, then the threads
are processes... but they *are* lightweight processes!)
[Lee]
{
http://pauillac.inria.fr/~xleroy/linuxthreads/README says that
threads not sharing parent's pid is a known bug (see "KNOWN BUGS
AND LIMITATIONS" section). Is it right?
Can you see a new process besides "java" process after java calls
a native method? I made a simple jni code, run it and couldn't
find extra process besides "java" by using "ps -a". The native
method is a infinity loop, so I have time to check ps.
}
Nathan
--
To UNSUBSCRIBE, email to [EMAIL PROTECTED]
with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]
--
To UNSUBSCRIBE, email to [EMAIL PROTECTED]
with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]
RE: Thread in the Linux's JVM
Nathan,
I really appreciate your valuable information. It helps a lot.
Pardon me for one more question - how to check thread status from command
line (like "ps" is used to check process status from command line) on Linux?
I'm new in Linux.
Regards,
Lee
-Original Message-
From: Nathan Meyers [mailto:[EMAIL PROTECTED]]
Sent: Friday, November 19, 1999 4:36 PM
To: [EMAIL PROTECTED]
Cc: [EMAIL PROTECTED]; [EMAIL PROTECTED]
Subject: Re: Thread in the Linux's JVM
On Fri, Nov 19, 1999 at 03:54:42PM -0600, [EMAIL PROTECTED] wrote:
>
> [Nathan]
> The JVM is a multi-threaded native application. Most of the time it's
> running native code that implements an interpreter, but some of the time
> it's running native code that doesn't happen to be in the interpreter
> (such as JNI methods or JIT-compiled code)
>
> [Lee]
> {
> This is a great comment! I didn't pay attention to the
> simple but important fact - "The JVM is a multi-threaded
> native application". Can we say that when java calls a native
> method, what really happens is JVM, the native application,
> loads a shared lib into its (JVM's) memory space and invokes
> one of the shared lib's methods. Therefore, no new thread is
> created at the time when java calls a native method. Is it
> right or I miss something again here?
You got it! The shared library is loaded into the JVM's shared library
address space when Java executes the System.loadLibrary() call.
> [Lee]
> If it's true, then why you say "When Java creates a native
> thread" below? Is a new thread really created when java calls
> a native method, and how?
No. A new thread is created when Java code invokes Thread.start().
It's an explicit operation, and certainly not something that just
happens when you jump between Java and native code.
Native code can also create new threads with pthread_create(), but
they need to "attach" to the Java JVM so the JVM knows about them.
> [Nathan]
> The important thing is that both the JVM and your native code use the
> same threading mechanism. Since you're using pthread_create() to create
> threads, you need to run a version of the JVM (native) that uses the
> same system. AFAIK, there's no way for JNI code to create new threads
> in a green thread environment.
>
> [Lee]
> {
> They uses the same threading mechanism or the same thread?
> }
Same *mechanism*. When you run with native threads, you run a version of
the JVM that creates its threads with pthread_create() - just like your
native code is doing. When you run with green threads, you're running
with a threading emulation library from Sun that has its own API, isn't
accessible from your native code, and will tend to crash and burn if
someone in the process space creates threads with pthread_create().
The thing to understand about green threads is that they were Sun's way
of getting Java onto a lot of platforms before those platforms had good
native threading mechanisms. Even today, as the Blackdown team struggles
with Linux's threading quirks, the green-threaded version of the JVM
tends to be more reliable. Green threads have their own interesting
"features": they're not preemptive, and they're not available to native
code that wants to create or manage threads. But they work.
> [Nathan]
> At any rate, all threads (native or green) are running "in the same
> process". With native threads, however, different threads have their
> own PIDs and entries in the process table, which results in confusing
> "ps" results. (Which is why I put "in the same process" in quotes - if
> you define a "process" as something with its own PID, then the threads
> are processes... but they *are* lightweight processes!)
>
> [Lee]
> {
> http://pauillac.inria.fr/~xleroy/linuxthreads/README says that
> threads not sharing parent's pid is a known bug (see "KNOWN BUGS
> AND LIMITATIONS" section). Is it right?
>
> Can you see a new process besides "java" process after java calls
> a native method? I made a simple jni code, run it and couldn't
> find extra process besides "java" by using "ps -a". The native
> method is a infinity loop, so I have time to check ps.
Again, calling JNI methods doesn't create a new thread... calling
Thread.start() does. That's why you don't see a new thread just by
calling native code.
The information in that README file is correct; it happens just as much
with multi-threaded C++ applications as with Java. But it's a limitation,
not a bug. This "feature", along with some others (for example, how the
thread stacks are laid out in the address space), makes it difficult to
create a multi-threaded application with more than a few hundred threads.
Now, applications with hundreds of threads are arguably employing Bad
Programming Practice, but there are developers who will defend to the
death their right to create such applications and who consider the
per-thread use of precious resources (s
RE: Nathan's Book
Hi Nathan: Are you going to make a new version of this book recently? Thank. Lee -Original Message- From: Jacob Nikom [mailto:[EMAIL PROTECTED]] Sent: Monday, January 10, 2000 11:19 AM To: Nathan Meyers Cc: Rich Ibbotson; [EMAIL PROTECTED] Subject: Re: Nathan's Book Does "Java Programming for Linux" have anything about programming Java 3D on Linux? Jacob Nikom Nathan Meyers wrote: > > Rich Ibbotson wrote: > > > > I realize that this is way off-topic for this list, and I apologize for that... > > But there's a rather nice web-site put together by Steve Wells and Brian Gannon > > that compares prices of books at a number of on-line sites: > > http://www.snmputils.com/booksearch/ > > It's amazing how the prices vary. For example, a search for Nathan Meyers' > > "Java Programming for Linux" (ISBN 1571691669) turns up: > > I don't entirely believe these results. Early pricing information from > the publisher was based on a low pagecount estimate, and some > booksellers are taking time to catch up to the final list price. You'll > need to visit the vendor and see what list price they're claiming to > discount - if it's not $49.99, then you're not seeing their real > discount price. > > Nathan > > > > > SITE PRICE > > VCSS $29.99 > > KingBooks$31.99 > > Borders $34.99 > > BookStreet $35.99 > > BooksaMillion$39.99 > > BookBuyer$42.49 > > Amazon $42.49 > > Powells $49.99 > > Softpro $49.99 > > > > And no, I'm not affiliated with any of these stores or the authors of the above > > site/PERL-script. I just use it a lot. > > > > Rich Ibbotson > > [EMAIL PROTECTED] > > > > Weiqi Gao wrote: > > > > > > Hi, > > > > > > I saw Nathan Meyers' new 'Java Programming for Linux' at Borders. > > > Browsed through it and found it packed with information that a > > > Java-Linux developer would want/need/find indespensable. Not a > > > textbook/tutorial. Lots of hints, tools, de-hype-ifications, whys, and > > > coverage. The spirit of Linux shines through throughout. > > > > > > I'm buying it from Amazon.com, they are giving a $7.50 discount on this > > > book. > > > > > > Thank Nathan you for such a wonderful book. And have fun updating it > > > every year for the next five years. You are going to update it, aren't > > > you? > > > > > > -- > > > Weiqi Gao > > > [EMAIL PROTECTED] > > > > > > -- > > > To UNSUBSCRIBE, email to [EMAIL PROTECTED] > > > with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED] > > > > -- > > To UNSUBSCRIBE, email to [EMAIL PROTECTED] > > with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED] > > -- > To UNSUBSCRIBE, email to [EMAIL PROTECTED] > with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED] -- To UNSUBSCRIBE, email to [EMAIL PROTECTED] with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED] -- To UNSUBSCRIBE, email to [EMAIL PROTECTED] with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]
RE: Nathan's Book
Thanks, Nathan. Yes, it's copyright 2000. The reason I asked the question because I couldn't find any topic on internationalization from the book. It would be appreciated if you could give me some information on how to implement this (i.e. display Japanese or Chinese on buttons, listbox, menu, etc.) in Java-Linux environment. Is there any web sites containing this kind of information? I like your book. It helps a lot. Thank you. BTW, did this maillist add a "filter"? I posted something recently, but it is never shown up. Lee -Original Message- From: Nathan Meyers [mailto:[EMAIL PROTECTED]] Sent: Wednesday, January 12, 2000 5:24 PM To: [EMAIL PROTECTED]; [EMAIL PROTECTED] Cc: [EMAIL PROTECTED] Subject: Re: Nathan's Book On Tue, Jan 11, 2000 at 10:01:00AM -0600, [EMAIL PROTECTED] wrote: > Hi Nathan: > > Are you going to make a new version of this book recently? It just came out! The book's Web site will help keep the information up to date. Publishers don't even think about revised editions until the book has been out awhile and done well in the marketplace. Maybe a year or two down the road... Nathan Meyers [EMAIL PROTECTED] Book Web Site: http://www.javalinux.net > > Thank. > > > Lee > > -Original Message- > From: Jacob Nikom [mailto:[EMAIL PROTECTED]] > Sent: Monday, January 10, 2000 11:19 AM > To: Nathan Meyers > Cc: Rich Ibbotson; [EMAIL PROTECTED] > Subject: Re: Nathan's Book > > > Does "Java Programming for Linux" have anything about programming Java > 3D on Linux? > > Jacob Nikom > > Nathan Meyers wrote: > > > > Rich Ibbotson wrote: > > > > > > I realize that this is way off-topic for this list, and I apologize for > that... > > > But there's a rather nice web-site put together by Steve Wells and Brian > Gannon > > > that compares prices of books at a number of on-line sites: > > > http://www.snmputils.com/booksearch/ > > > It's amazing how the prices vary. For example, a search for Nathan > Meyers' > > > "Java Programming for Linux" (ISBN 1571691669) turns up: > > > > I don't entirely believe these results. Early pricing information from > > the publisher was based on a low pagecount estimate, and some > > booksellers are taking time to catch up to the final list price. You'll > > need to visit the vendor and see what list price they're claiming to > > discount - if it's not $49.99, then you're not seeing their real > > discount price. > > > > Nathan > > > > > > > > SITE PRICE > > > VCSS $29.99 > > > KingBooks$31.99 > > > Borders $34.99 > > > BookStreet $35.99 > > > BooksaMillion$39.99 > > > BookBuyer$42.49 > > > Amazon $42.49 > > > Powells $49.99 > > > Softpro $49.99 > > > > > > And no, I'm not affiliated with any of these stores or the authors of > the above > > > site/PERL-script. I just use it a lot. > > > > > > Rich Ibbotson > > > [EMAIL PROTECTED] > > > > > > Weiqi Gao wrote: > > > > > > > > Hi, > > > > > > > > I saw Nathan Meyers' new 'Java Programming for Linux' at Borders. > > > > Browsed through it and found it packed with information that a > > > > Java-Linux developer would want/need/find indespensable. Not a > > > > textbook/tutorial. Lots of hints, tools, de-hype-ifications, whys, > and > > > > coverage. The spirit of Linux shines through throughout. > > > > > > > > I'm buying it from Amazon.com, they are giving a $7.50 discount on > this > > > > book. > > > > > > > > Thank Nathan you for such a wonderful book. And have fun updating it > > > > every year for the next five years. You are going to update it, > aren't > > > > you? > > > > > > > > -- > > > > Weiqi Gao > > > > [EMAIL PROTECTED] > > > > > > > > -- > > > > To UNSUBSCRIBE, email to [EMAIL PROTECTED] > > > > with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED] > > > > > > -- > > > To UNSUBSCRIBE, email to [EMAIL PROTECTED] > > > with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED] > > > > -- > > To UNSUBSCRIBE, email to [EMAIL PROTECTED] > > with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED] > > > -- > To UNSUBSCRIBE, email to [EMAIL PROTECTED] > with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED] -- [EMAIL PROTECTED] Public Access User -- Not affiliated with Teleport Public Access UNIX and Internet at (503) 220-1016 (2400-28800, N81) -- To UNSUBSCRIBE, email to [EMAIL PROTECTED] with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]
RE: Nathan's Book
-Original Message- From: Nathan Meyers [mailto:[EMAIL PROTECTED]] Sent: Wednesday, January 12, 2000 5:46 PM To: [EMAIL PROTECTED] Cc: [EMAIL PROTECTED] Subject: Re: Nathan's Book On Wed, Jan 12, 2000 at 05:37:22PM -0600, [EMAIL PROTECTED] wrote: > Thanks, Nathan. > > Yes, it's copyright 2000. The reason I asked the question because I > couldn't find any topic on internationalization from the book. It would be > appreciated if you could give me some information on how to implement this > (i.e. display Japanese or Chinese on buttons, listbox, menu, etc.) in > Java-Linux environment. Is there any web sites containing this kind of > information? Afraid I haven't spent much time in this area. The JDK implements a lot of its own I18N capabilities, although there is clearly some reliance on the native environment. What I18N issues have you identified specific to Linux? Nathan [Lee] I'm new in this area too (and new in Java-Linux as well). The issue of I18N I have is very basic at this time. That is what we need and need to do to display Japanese and Chinese characters on a JButton on Linux. Q1: Do we need a Japanese/Chinese font packages? Q2: If so, where to find the right font package for Linux? Q3: After find the font package, how to use it to show a Japanese/Chinese character on a JButton? Q4: Is there any Japanese/Chinese version of Linux like Windows NT does? It would be appreciated if you could give me a hint. Lee -- To UNSUBSCRIBE, email to [EMAIL PROTECTED] with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]
RE: Nathan's Book
Thank you for your help, Nathan. Regards, Lee -Original Message- From: Nathan Meyers [mailto:[EMAIL PROTECTED]] Sent: Wednesday, January 12, 2000 6:27 PM To: [EMAIL PROTECTED] Cc: [EMAIL PROTECTED] Subject: Re: Nathan's Book On Wed, Jan 12, 2000 at 06:14:17PM -0600, [EMAIL PROTECTED] wrote: > Q4: Is there any Japanese/Chinese version of Linux like Windows NT does? I'll take a stab at answering this one. The TurboLinux distro is the big name in Asia: they've done a lot of work on I18N and L10N. I would start by trying to use the JDK in that environment. Nathan > > > -Original Message- > From: Nathan Meyers [mailto:[EMAIL PROTECTED]] > Sent: Wednesday, January 12, 2000 5:46 PM > To: [EMAIL PROTECTED] > Cc: [EMAIL PROTECTED] > Subject: Re: Nathan's Book > > > On Wed, Jan 12, 2000 at 05:37:22PM -0600, [EMAIL PROTECTED] wrote: > > Thanks, Nathan. > > > > Yes, it's copyright 2000. The reason I asked the question because I > > couldn't find any topic on internationalization from the book. It would > be > > appreciated if you could give me some information on how to implement this > > (i.e. display Japanese or Chinese on buttons, listbox, menu, etc.) in > > Java-Linux environment. Is there any web sites containing this kind of > > information? > > Afraid I haven't spent much time in this area. The JDK implements a lot > of its own I18N capabilities, although there is clearly some reliance > on the native environment. What I18N issues have you identified specific > to Linux? > > Nathan > > [Lee] > I'm new in this area too (and new in Java-Linux as well). The issue of I18N > I have is very basic at this time. That is what we need and need to do to > display Japanese and Chinese characters on a JButton on Linux. > > Q1: Do we need a Japanese/Chinese font packages? > Q2: If so, where to find the right font package for Linux? > Q3: After find the font package, how to use it to show a Japanese/Chinese > character on a JButton? > Q4: Is there any Japanese/Chinese version of Linux like Windows NT does? > > It would be appreciated if you could give me a hint. > > > Lee -- [EMAIL PROTECTED] Public Access User -- Not affiliated with Teleport Public Access UNIX and Internet at (503) 220-1016 (2400-28800, N81) -- To UNSUBSCRIBE, email to [EMAIL PROTECTED] with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]
RE: Java-Linux I18N
Renzo:
Thank you very much for your help and information. It's very helpful.
I'll send time to digest all of the information and give it a try.
Regards,
PS. This msg may not be able to be posted in the mail list. I don't know
why.
Lee
-Original Message-
From: Renzo Pecoraro [mailto:[EMAIL PROTECTED]]
Sent: Friday, January 14, 2000 2:15 PM
To: [EMAIL PROTECTED]
Subject: Java-Linux I18N
Couple of hints on this.
So far, I haven't seen anything in Java I18N that's specific to Linux,
except:
1. Yes, you need Asian fonts. Some come with the distros, I got
additional ones from
http://www.userfriendly.net/linux/RPM/rhcn/noarch/X11_fonts.html
(Japanese, Simplified Chinese, Traditional Chinese, Korean) - these are
all RPMs
2. You do need to change you font.properties file in order to display
Asian in a Java program. But once you have that, you can display it,
even if your machine uses the Western European codepage (i.e.is set up
to behave as a Western European/US machine) - EXCEPT, as of pre-Swing,
TextField and TextArea will NOT display Asian, because these components
use native code (or for whatever reason). From what I understand Swing
components do not have that limitation. Now, there's a great site for
Japanese Linux at
http://hikari.tlug.gr.jp/~craigoda/writings/linux-nihongo/linux-nihongo.html
,
including references to Java, and most importantly a font.properties
file for Linux. I simply downloaded that file, dropped it into my
../jre/lib directory of Java installation and into
/usr/lib/netscape/java/classes for my netscape browser. BUT, if you
backup your existing font.properties file (as you would want to) to
java.properties.en (as it would logically be named), your JVM (of the
JRE or Netscape's) seems to still look up the fonts described in that
backed up file, if your machine's default Locale is English. So I backed
mine up to font.properties.ENGLISH (which the JVM apparently cannot map
to my machines Locale), and then it works beautifully - EXCEPT that some
Western European fonts are now not quite so pretty. Of course, you can
and probably should edit that font.properties file, but the one
downloaded from
http://hikari.tlug.gr.jp/~craigoda/writings/linux-nihongo/linux-nihongo.html
is a great starting point.
3. I am fairly certain that there is a way to switch the locale and
charset/codepage of your machine (hence the /etc/charset directory, I'd
think), but I haven't figured it out yet (although I will have to for a
project sometime soon).
4. From what I can tell, the rest is Java I18N as usual. See the I18N
Tutorial at http://java.sun.com/docs/books/tutorial/i18n/TOC.html. There
was also a three-part tutorial at http://www.javaworld.com at somepoint.
Take the first first example of that tutorial and add Japanese to the
choices ("ja", "JP") to allow you to test whether you have correctly
installed the font.properties file. If you did, you'll see Japanese
characters when you select Japanese in this applet (in appletviewer or
in the browser).
Hope this helps.
Renzo
> > [Lee]
> > I'm new in this area too (and new in Java-Linux as well). The issue of
> I18N
> > I have is very basic at this time. That is what we need and need to do
to
> > display Japanese and Chinese characters on a JButton on Linux.
> >
> > Q1: Do we need a Japanese/Chinese font packages?
> > Q2: If so, where to find the right font package for Linux?
> > Q3: After find the font package, how to use it to show a
Japanese/Chinese
> > character on a JButton?
> > Q4: Is there any Japanese/Chinese version of Linux like Windows NT does?
--
To UNSUBSCRIBE, email to [EMAIL PROTECTED]
with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]
--
To UNSUBSCRIBE, email to [EMAIL PROTECTED]
with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]
JNI and Dead Thread on Linux
Hi: I got a few questions on JNI on Linux. It would be appreciated if someone could help. Suppose a shared library file has a function that is used to do hardware I/O, say hard drives R/W. A Java application uses JNI and calls this native function in .so file twice to R/W two separate hard drives at the same time. In this way, we should have two new threads (light weight processes) t1 and t2 created (am I right?). Q1: Since Java application and two newly-created threads (t1 and t2) share the same memory space, if t1 messes up memory space and hangs, then Java application and t2 will hang too, right? Q2: If the answer to Q1 is "right", is it possible to protect Java application and t2 and prevent them from hanging after t1 is hung if we use JNI? Q3: If the answer to Q2 is "no", then do you think out-proc solutions (i.e. leave native functions in different memory spaces) like CORBA, TCP/IP and DCOM (not sure it's available now or not on Linux) are better than in-proc solution like JNI, so we can separate native functions in different memory spaces and prevent one from messing others? Is there any potential problem? Thank you in advance. Lee -- To UNSUBSCRIBE, email to [EMAIL PROTECTED] with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]
RE: JNI and Dead Thread on Linux
Hi Nathan: Thank you for the information and sorry for the careless mistake. Based on your book and information posted on the mail list. It seems: Q1: There are only two ways to create new threads when use JNI on Linux (and other OS). (a) use Thread.start in java code. (b) let native code create a thread by using pthread_create and attach the newly-created thread to JVM, so JVM, the multi- threaded application, will create a sort of "internal thread" for the attached native thread, right? Q2: if use the first method, to make the new thread be created in OS kernel, we need to use "java -native" to run the application. If use "java -green", then the new thread won't be created in OS kernel and it's fully controlled by JVM therefore it's in user space and non-preemptive. if use the second method, we have to use "java -native" to run the application because native code uses native lib (pthread_create) to create the thread. If "java -green" were used to run it, would run into problems. Do I understand them right? Q3: With BlackDown 117_v3, the default behavior should be "green". I can run a simple java application with "java app" or "java -green app" without any problem (they are the same,right?). But got an error msg like "java was not found in /usr/local/jdk117_v3/bin/../bin/i686/native_threads/java" when run it with "java -native app". Do I miss something? Q4: What compile options I need to specify to pick up the right lib if I want to run java app with green or native thread? Thank you. Lee -Original Message- From: Nathan Meyers [mailto:[EMAIL PROTECTED]] Sent: Tuesday, January 18, 2000 2:20 PM To: [EMAIL PROTECTED]; [EMAIL PROTECTED] Cc: [EMAIL PROTECTED] Subject: Re: JNI and Dead Thread on Linux On Tue, Jan 18, 2000 at 11:28:17AM -0600, [EMAIL PROTECTED] wrote: > Hi: > > I got a few questions on JNI on Linux. It would be appreciated if someone > could help. > > Suppose a shared library file has a function that is used to do hardware > I/O, say hard drives R/W. A Java application uses JNI and calls this native > function in .so file twice to R/W two separate hard drives at the same time. > In this way, we should have two new threads (light weight processes) t1 and > t2 created (am I right?). Calling into native code doesn't create new threads - it just moves the flow of control from the Java interpreter into some other native code. After the JNI method returns, you're back to executing native code in the Java interpreter. Nathan > > Q1: Since Java application and two newly-created threads (t1 and t2) share > the same memory space, if t1 messes up memory space and hangs, then Java > application and t2 will hang too, right? > > Q2: If the answer to Q1 is "right", is it possible to protect Java > application and t2 and prevent them from hanging after t1 is hung if we use > JNI? > > Q3: If the answer to Q2 is "no", then do you think out-proc solutions (i.e. > leave native functions in different memory spaces) like CORBA, TCP/IP and > DCOM (not sure it's available now or not on Linux) are better than in-proc > solution like JNI, so we can separate native functions in different memory > spaces and prevent one from messing others? Is there any potential problem? > > > Thank you in advance. > > > > Lee -- [EMAIL PROTECTED] Public Access User -- Not affiliated with Teleport Public Access UNIX and Internet at (503) 220-1016 (2400-28800, N81) -- To UNSUBSCRIBE, email to [EMAIL PROTECTED] with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]
RE: JNI and Dead Thread on Linux
Hi Nathan: Thank you for your information. I downloaded jdk_1.1.7-v3-glibc-x86-native.tar.gz and unpack it from the $JAVA_HOME directory. When I run "java -native app", I got an error message like: "Cannot open /proc/00762 for GC/mnt/e/Linux/java/jni/Sample3/app", and every time when I re-try "java -native app", the number 00762 is changed to another number. Nothing fancy in app. It's only a helloWorld application, and located in /mnt/e/Linux/java/jni/Sample3/ I guess JVM tried to create a native thread since each process (heavyweight or light) has a corresponding directory under /proc dir. BTW, this happened on RH6.1 and I run the app as root. "java app" and "java -green app" work fine. I don't know what GC (before /mnt/e...) is. Thank you. Lee > > Q3: With BlackDown 117_v3, the default behavior should be "green". > I can run a simple java application with "java app" or > "java -green app" without any problem (they are the same,right?). > But got an error msg like "java was not found in > /usr/local/jdk117_v3/bin/../bin/i686/native_threads/java" when > run it with "java -native app". Do I miss something? > > Q4: What compile options I need to specify to pick up the right lib > if I want to run java app with green or native thread? No changes needed with compiling. The reason you can't run native is that you don't have a native version installed in your JDK installation tree. Visit a mirror site and grab jdk_1.1.7-v3-glibc-x86-native.tar.gz: unpack it from the $JAVA_HOME directory and you'll get the native versions. By way of background, the decision on which threading model to use is made in the script ($JAVA_HOME/bin/java) that launches the java executable: it looks at "-green" or "-native" (yes, it defaults to green), sets up the environment, and decides which actual executable (green or native) to run. Nathan > > Thank you. > > Lee > -- To UNSUBSCRIBE, email to [EMAIL PROTECTED] with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]
RE: JNI and Dead Thread on Linux
Thanks, Juergen.
Yes. 1.1.8-v1 fixed this problem.
I got two questions on JNI and thread. Could someone help me on these?
Thank you.
Environment: RH6.1, BlackDown 1.1.8_v1
Q1:
After start the following simple java application
by using "java -native test",
public class test
{
public static void main(String args[])
{
while(true)
{
;
}
}
}
command line command "ps -a" shows 4 java (JVM) running.
Why there are so many JVMs running, and what they are for?
Q2:
I want to load *.so file in a class other than java application's
public class. In this way, the shared lib files are loaded only
when they are needed. But the following code doesn't work.
public class ShowMsgBox
{
static public void main(String args[])
{
toNative app = new toNative();
app.ShowMessage("test from Java app");
}
}
class toNative
{
toNative()
{
System.loadLibrary("MsgImpl");
}
native void ShowMessage(String msg);
}
Got an error msg when run it, the error msg is:
"java.lang.UnsatisfiedLinkError: ShowMessage at
ShowMsgBox.main(ShowMsgBox.java:6)"
It seems libMsgImpl.so is loaded OK, otherwise, it complains about file not
found.
What did I do wrong?
Thank you.
Lee
-Original Message-
From: Juergen Kreileder [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, January 25, 2000 12:38 PM
To: [EMAIL PROTECTED]
Cc: [EMAIL PROTECTED]; [EMAIL PROTECTED]
Subject: Re: JNI and Dead Thread on Linux
> Lee Xing writes:
Lee> Hi Nathan:
Lee> Thank you for your information.
Lee> I downloaded jdk_1.1.7-v3-glibc-x86-native.tar.gz and unpack it
Lee> from the $JAVA_HOME directory. When I run "java -native app", I
Lee> got an error message like:
Lee> "Cannot open /proc/00762 for GC/mnt/e/Linux/java/jni/Sample3/app",
This problem has been fixed in 1.1.8-v1.
Juergen
--
Juergen Kreileder, Blackdown Java-Linux Team
http://www.blackdown.org/java-linux.html
--
To UNSUBSCRIBE, email to [EMAIL PROTECTED]
with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]
RE: JNI and Dead Thread on Linux
-Original Message-
From: Jo Uthus [mailto:[EMAIL PROTECTED]]
Sent: Thursday, January 27, 2000 1:31 AM
To: [EMAIL PROTECTED]
Cc: [EMAIL PROTECTED]
Subject: Re: JNI and Dead Thread on Linux
[EMAIL PROTECTED] wrote:
| Q1:
|
| command line command "ps -a" shows 4 java (JVM) running.
| Why there are so many JVMs running, and what they are for?
Threads in Linux show up as processes when using 'ps' or 'top'.
[Lee]
But the code has only a infinity loop and doesn't create any thread
or process.
| Q2:
|
| I want to load *.so file in a class other than java application's
| public class. In this way, the shared lib files are loaded only
| when they are needed. But the following code doesn't work.
|
[snip]
| System.loadLibrary("MsgImpl");
[snip]
| Got an error msg when run it, the error msg is:
| "java.lang.UnsatisfiedLinkError: ShowMessage at
| ShowMsgBox.main(ShowMsgBox.java:6)"
Try putting libMsgImpl.so in /usr/local/java/jre/lib/i386/ (or
wherever you have your javaVM located)
| What did I do wrong?
cp libMsgImpl.so /usr/local/lib/javanative/
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib/javanative/
[Lee]
I follow your instruction and put libMsgImpl.so in
/usr/local/jdk118_v1/bin/i686/native_threads, and
/usr/local/jdk118_v1/lib/i686/native_threads, and
export
LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/jdk118_v1/lib/i686/native_thread
s
But the same problem is still there. I think libMsgImpl.so is loaded OK,
otherwise
error will be like "libMsgImpl.so not found". The problem is why I couldn't
call a native
function declared in a class other than java application's public class.
--
Jo Uthus| e-mail: [EMAIL PROTECTED] (private)
Software Engineer | e-mail: [EMAIL PROTECTED] (work)
--
To UNSUBSCRIBE, email to [EMAIL PROTECTED]
with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]
RE: JNI and Dead Thread on Linux
Juergen,
Thank you and all other people responding to my e-mail.
Yes, you are right. I forgot to change the function name in C file after
moved the native function declaration into another java class. Sorry for
the careless mistake.
Regards,
Lee
-Original Message-
From: Juergen Kreileder [mailto:[EMAIL PROTECTED]]
Sent: Thursday, January 27, 2000 5:24 PM
To: [EMAIL PROTECTED]
Cc: [EMAIL PROTECTED]; [EMAIL PROTECTED]
Subject: Re: JNI and Dead Thread on Linux
> Lee Xing writes:
Lee> -Original Message-
Lee> From: Jo Uthus [mailto:[EMAIL PROTECTED]]
Lee> Sent: Thursday, January 27, 2000 1:31 AM
Lee> To: [EMAIL PROTECTED]
Lee> Cc: [EMAIL PROTECTED]
Lee> Subject: Re: JNI and Dead Thread on Linux
Lee> [EMAIL PROTECTED] wrote:
Lee> | Q1:
Lee> |
Lee> | command line command "ps -a" shows 4 java (JVM) running.
Lee> | Why there are so many JVMs running, and what they are for?
Lee> Threads in Linux show up as processes when using 'ps' or 'top'.
Lee> [Lee]
Lee> But the code has only a infinity loop and doesn't create any thread
Lee> or process.
Java uses threads internally too. E.g. one thread for the GC, one for
handling SIGQUIT, ... You'll get thread dump by sending SIGQUIT to
java (e.g. press Ctrl-\ in shell where you've started java).
Lee> | Q2:
Lee> |
Lee> | I want to load *.so file in a class other than java application's
Lee> | public class. In this way, the shared lib files are loaded only
Lee> | when they are needed. But the following code doesn't work.
Lee> |
Lee> [snip]
Lee> | System.loadLibrary("MsgImpl");
Lee> [snip]
Lee> | Got an error msg when run it, the error msg is:
Lee> | "java.lang.UnsatisfiedLinkError: ShowMessage at
Lee> | ShowMsgBox.main(ShowMsgBox.java:6)"
This means that java can't find the native implementation of
ShowMessage, check the name of your C function.
Juergen
--
Juergen Kreileder, Blackdown Java-Linux Team
http://www.blackdown.org/java-linux.html
--
To UNSUBSCRIBE, email to [EMAIL PROTECTED]
with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]
RE: Java-Linux I18N Tutorial
Hi Renzo: Thank you for the information you put together. It helps. Regards, Lee -Original Message- From: Renzo Pecoraro [mailto:[EMAIL PROTECTED]] Sent: Monday, January 31, 2000 2:14 AM To: [EMAIL PROTECTED] Subject: Java-Linux I18N Tutorial All - I started a little Java-Linux I18N Tutorial at http://www.renzop.com. It includes a custom font.properties file and instructions for Linux that allows you to use the gnu-unifont in your browser/JDK/JRE. This is a work in progress and comments/questions are greatly appreciated. Thanks. Renzo -- To UNSUBSCRIBE, email to [EMAIL PROTECTED] with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED] -- To UNSUBSCRIBE, email to [EMAIL PROTECTED] with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]
JNI & .so Files
Hi, I got a question on JNI. It would be appreciated if someone could help. Q: In order to hide java and jni related issues (e.g. jni function name convention, etc.) from .so programmers, a wrapper .so file so1.so is used in between java app and another .so file so2.so (the one with native functions we need). This way, the java app interacts with the wrapper so1.so directly. Every time when java app needs a native function service in so2.so, it first calls a native function in so1.so through jni. so1.so, in turn, calls the required function in so2.so. Everything works fine in this direction (i.e. java app->so1.so->so2.so. java app loads so1.so, and so1.so loads so2.so, then java app invokes a function in so2.so through a function in so1.so). The question is how a function in so2.so calls back to java app through a function in so1.so? In fact, we only need to know how functions in so2.so can call functions in so1.so because jni will let us call back to java app from so1.so. More information: - the java app is multithreaded application using Thread.start(). - each java thread may call the same function in so1.so, then this function, in turn, calls a function in so2.so - native code doesn't create any thread. Use IPC? which one is easier on Linux? Is there any other mechanism for this on Linux? A simple sample code will help a lot. Thank you. Lee -- To UNSUBSCRIBE, email to [EMAIL PROTECTED] with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]
RE: JNI & .so Files
Hi Nathan,
Thank you for your response. Please let me re-address my question by using
the following pseudo code. I embedded my question in so2.c pseudo code.
The following lines are app.java, so1.c and so2.c. They are only pseudo
code.
==
//app.java
public class app
{
static
{
System.loadLibrary("so1");
}
native void so1Func();
public static void main(String args[])
{
app myApp = new app();
myApp.so1Func();
}
javaFunc()
{
System.out.printfln("In Java, called back from so1.so");
}
}
==
//so1.c for libso1.so
JNIEnv gEnv;
jobject gObj;
void Java_app_so1Func(JNIEnv * jEnv, jobject _this)
{
gEnv = jEnv;
gObj = _this;
...
library = dlopen("./libso2.so", RTLD_LAZY);
funcRef = dlsym(library, "so2Func");
(*funcRef)(); //call function so2Func() in libso2.so
...
}
void callBack()
{
jclass cls = (*gEnv)->GetObjectClass(gEnv, gObj);
jmethodID mid = (*gEnv)->GetMethodID(gEnv, cls, "javaFunc", "(V)V");
(*gEnv)->CallVoidMethod(gEnv, gObj, mid); //call back to java app.
}
==
//so2.c for libso2.so
so2Func()
{
while(1)
{
...
//
//how to call back to the function
//callBack() in libso1.so from here?
//
...
}
}
app.java loads libso1.so into its address space, and libso1.so loads
libso2.so into the same address space. So, libso2.so should be able to call
a function in libso1.so (in the same address space) if libso2.so can resolve
that function's symbol, but how?
Thanks.
Lee
-Original Message-
From: Nathan Meyers [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, February 02, 2000 10:44 PM
To: [EMAIL PROTECTED]
Cc: [EMAIL PROTECTED]
Subject: Re: JNI & .so Files
[EMAIL PROTECTED] wrote:
>
> Hi,
>
> I got a question on JNI. It would be appreciated if someone could help.
Lee,
I'm having trouble understanding the problem you're posing. What is the
difficulty you're trying to solve... how to call functions in one .so
from another .so? You're already doing that.
Is it the problem of figuring out how to call a function whose name you
do not know until runtime? If so, I think you'll find the
dlopen()/dlsym()/dlclose() functions useful. Other than that
possibility, I'm not quite sure what problem you're trying to solve.
Nathan
>
> Q:
> In order to hide java and jni related issues (e.g. jni function name
> convention, etc.) from .so programmers, a wrapper .so file so1.so is used
in
> between java app and another .so file so2.so (the one with native
functions
> we need). This way, the java app interacts with the wrapper so1.so
> directly. Every time when java app needs a native function service in
> so2.so, it first calls a native function in so1.so through jni. so1.so,
in
> turn, calls the required function in so2.so. Everything works fine in
this
> direction (i.e. java app->so1.so->so2.so. java app loads so1.so, and
so1.so
> loads so2.so, then java app invokes a function in so2.so through a
function
> in so1.so). The question is how a function in so2.so calls back to java
app
> through a function in so1.so? In fact, we only need to know how functions
> in so2.so can call functions in so1.so because jni will let us call back
to
> java app from so1.so.
>
> More information:
> - the java app is multithreaded application using Thread.start().
> - each java thread may call the same function in so1.so, then
> this function, in turn, calls a function in so2.so
> - native code doesn't create any thread.
>
> Use IPC? which one is easier on Linux? Is there any other mechanism
> for this on Linux?
>
> A simple sample code will help a lot.
>
> Thank you.
>
> Lee
>
> --
> To UNSUBSCRIBE, email to [EMAIL PROTECTED]
> with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]
--
To UNSUBSCRIBE, email to [EMAIL PROTECTED]
with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]
RE: JNI & .so Files
Hi Nathan,
Thank you very much for your information. I created three small real files
(app.java, so1_beep.c and so2_hello.c) and attach them below. They can be
compiled into .class, .h, .o and .so files. I'm using BlackDown 1.1.8 v1 on
RH6.1
It seems so2 can call back to so1, but when so1 calls back to java app, a
segment error happens. I checked the code many times but still couldn't
figure out why. I have a feeling that saving JNIEnv and jobject in so1 to
global vars may have problem but not sure. Thank you and forgive me for
this long e-mail.
The error msg is long. It looks like:
SIGSEGV 11* segmentation violation
stackbase=B8C8, stackpointer=B248
Full thread dump:
...
...
app.main(app.java:8)
Monitor Cache Dump:
Registered Monitor Dump:
Thread queue lock:
Name and type hash table lock:
String intern lock:
JNI pinning lock:
JNI global reference lock:
BinClass lock:
Class loading lock:
Java stack lock:
Code rewrite lock:
Heap lock:
Has finalization queue lock:
Finalize me queue lock:
Waiting to be notified:
"Finalizer thread" (0x80af440)
Monitor registry: owner "main" (0x80a3b78, 1 entry)
Aborted
//app.java
public class app
{
static public void main(String args[])
{
System.out.println("*** in main() ***");
toNative app = new toNative();
app.loadSo2("*** call load_so2() from java ***");
}
}
class toNative
{
toNative()
{
System.loadLibrary("so1_beep");
}
native void loadSo2(String msg);
void callBack()
{
System.out.println("In Java, called back from so1");
}
}
//so1_beep.c
#include
#include
#include
#include "toNative.h"
JNIEnv *gEnv;
jobject gObj;
void Java_toNative_loadSo2(JNIEnv * jEnv, jobject _this, jstring jMsg)
{
void *library;
void (*soHello)(void);
const char *error;
gEnv = jEnv; //save them in global vars to let local function
gObj = _this; //backToJava() use them to call back to java app.
printf("*** so1: in loadSo2() before dlopen() ***\n");
library = dlopen("./libso2_hello.so", RTLD_LAZY);
if(library==NULL)
{
fprintf(stderr, "Could not open libso2_hello.so: %s\n",
dlerror());
exit(1);
}
dlerror();
soHello = (void *) dlsym(library, "print_hello");
error = dlerror();
if(error)
{
fprintf(stderr, "Could not find print_hello(): %s\n",
error);
exit(1);
}
(*soHello)();
}
void backToJava()
{
jclass cls = (*gEnv)->GetObjectClass(gEnv, gObj);
jmethodID mid = (*gEnv)->GetMethodID(gEnv, cls, "callBack", "(V)V");
printf("*** in backToJava() ***\n"); // I can see this msg after
run it
//and before the
segmentation error.
(*gEnv)->CallVoidMethod(gEnv, gObj, mid);
}
//so2_hello.c
#include
#include
#include
print_hello()
{
void (*backToSo1)(void);
void *library;
const char *error;
library = dlopen("./libso1_beep.so", RTLD_LAZY);
if(library==NULL)
{
fprintf(stderr, "Could not open libso1_beep.so in
libso2_hello.so:%s\n", dlerror());
exit(1);
}
dlerror();
backToSo1 = (void *) dlsym(library, "backToJava");
error = dlerror();
if(error)
{
fprintf(stderr, "Could not find backToJava(): %s\n", error);
exit(1);
}
while(1)
{
sleep(1);
(*backToSo1)();
}
}
-Original Message-
From: Nathan Meyers [mailto:[EMAIL PROTECTED]]
Sent: Thursday, February 03, 2000 1:27 PM
To: [EMAIL PROTECTED]
Cc: [EMAIL PROTECTED]; [EMAIL PROTECTED]
Subject: Re: JNI & .so Files
On Thu, Feb 03, 2000 at 12:28:25PM -0600, [EMAIL PROTECTED] wrote:
> Hi Nathan,
>
> Thank you for your response. Please let me re-address my question by
using
> the following pseudo code. I embedded my question in so2.c pseudo code.
Thanks, that helps. You're simply trying to get a symbol address so you
can call it. You could use the same technique in so2 that you used in
so1: dlopen() to load the library and dlsym() to look up a symbol.
Yes, it appears that dlopen() is redundant, since the so1 library is
already loaded... but that's not a problem. Calling dlopen() on that
library will not load another copy, it will just increase a refcount
maintained by the system. More importantly, it'll return a handle you
can use in a dlsym() call.
Nathan
RE: JNI & .so Files
Weiqi,
You are right. That's the problem. Sorry for the careless mistake.
To make the code more interesting, I add two threads, t1 and t2, in the code
this time and found some problems, maybe they are my problems again :(
Q1: Based on JNI spec, different native functions in the same thread should
get the same JNIEnv pointer, and native functions in different threads
should receive different JNIEnv pointers. In other words, JNIEnv pointer
should be thread unique. But I couldn't see this (see attached running
result and code). Also, I found jobjects passed to native function from
different calling objects are the same (again, see attached result and code)
when using BlackDown 1.1.8 v1. I run the same java app and dlls (same
contents as so1 and so2) on NT by using jdk 1.2 coming with VisualCafe4.0,
it seems jobjects passed to native function from different calling objects
are different (as expected, because native function is called from different
thread objects, t1 and t2. see attached code please). I don't know why the
behavior is different on Linux and NT (or between BlackDown 1.1.8 v1 and
jdk1.2)
Q2:
Based on the running result, it seems every time when call back from so1 to
so2 in either t1 or t2 thread context, so2 always uses the second thread
t2's *JNIEnv to call back to java. But we need so2 call back to so1 then
java in its own thread context.
Note: attached codes are real and can be compiled to .class, .h, .o and .so
Could someone take a look and see what I did wrong? I learned a lot
recently from this group.
Thank you and have a nice Lunar New Year!
Lee
===
///
//running result
///
/mnt/e/Linux/java/jni/java_so_so_4>java -native app
*** in main() ***
*** in t1's loadSo2, jEnv = -1086325736
*** in t1's loadSo2, *jEnv = 1074234656
*** in t1's loadSo2, _this = 1
*** hello from so2 ***
*** in t2's loadSo2, jEnv = -1088422888
*** in t2's loadSo2, *jEnv = 1074234656
*** in t2's loadSo2, _this = 1
*** hello from so2 ***
*** in t2's backToJava, gEnv = -1088422888
*** in t2's backToJava, *gEnv = 1074234656
*** in t2's backTojava, gObj = 1
* In Java, called back from so1
*** in t2's backToJava, gEnv = -1088422888
*** in t2's backToJava, *gEnv = 1074234656
*** in t2's backTojava, gObj = 1
* In Java, called back from so1
*** in t2's backToJava, gEnv = -1088422888
*** in t2's backToJava, *gEnv = 1074234656
*** in t2's backTojava, gObj = 1
* In Java, called back from so1
*** in t2's backToJava, gEnv = -1088422888
*** in t2's backToJava, *gEnv = 1074234656
*** in t2's backTojava, gObj = 1
* In Java, called back from so1
/mnt/e/Linux/java/jni/java_so_so_4>
===
///
//app.java
///
public class app
{
static public void main(String args[])
{
System.out.println("*** in main() ***");
myThread t1 = new myThread("t1");
myThread t2 = new myThread("t2");
t1.start();
t2.start();
}
static
{
System.loadLibrary("so1_beep");
}
}
class myThread extends Thread
{
myThread(String tID)
{
super(tID);
}
native void loadSo2(String msg);
public void run()
{
loadSo2(this.getName());
}
void callBack()
{
System.out.println("* In Java, called back from so1\n");
}
}
===
///
//so1_beep.c
///
#include
#include
#include
#include "myThread.h"
JNIEnv *gEnv;
jobject gObj;
char szTmp[20];
void Java_myThread_loadSo2(JNIEnv * jEnv, jobject _this, jstring jMsg)
{
void *library;
void (*soHello)(void);
const char *error;
const char * msg;
msg = (*jEnv)->GetStringUTFChars(jEnv, jMsg, 0);
printf("*** in %s's loadSo2, jEnv = %d\n", msg, jEnv);
printf("*** in %s's loadSo2, *jEnv = %d\n", msg, *jEnv);
printf("*** in %s's loadSo2, _this = %d\n", msg, _this);
strcpy(szTmp, msg);
(*jEnv)->ReleaseStringUTFChars(jEnv, jMsg, msg);
gEnv = jEnv;
gObj = _this;
library = dlopen("./libso2_hello.so", RTLD_LAZY);
if(library==NULL)
{
fprintf(stderr, "Could not open libso2_hello.so: %s\n",
dlerror());
exit(1);
}
dlerror();
soHello = (void *) dlsym(library, "print_hello");
error = dlerror();
if(error)
{
fprintf(stderr, "Could not find print_hello(): %s\n",
error);
exit(1);
}
(*soHello)();
}
void backToJava()
{
jclass cls = (*gEnv)->GetObjectClass(gEnv, gObj);
jmethodID mid = (*gEnv)->GetMe
RE: JNI & .so Files
Thanks, Weiqi. Yes it works. Is it for two threads only? Regards, Lee -Original Message- From: Weiqi Gao [mailto:[EMAIL PROTECTED]] Sent: Friday, February 04, 2000 12:57 PM To: [EMAIL PROTECTED]; [EMAIL PROTECTED] Subject: Re: JNI & .so Files [EMAIL PROTECTED] wrote: > > [accessing global variables from different threads] Your so1_beep.c is not thread-safe. And sure enough it crashes when called from multiple threads. Making it thread safe means that you have to make the changes specified in the Multithreaded Programming Guide. Linux doesn't seem to have a guide like this. Balenhof's Pthreads book or the Sun Multithreaded programming guide (http://docs.sun.com) are good starting points. But then we are not talking about Java anymore. Maybe comp.programming.threads is a more appropriate forum. I have made jsut enough of the changes to make the program 'work'. See the attachment. -- Weiqi Gao [EMAIL PROTECTED] = Weiqi Gao [EMAIL PROTECTED] __ Do You Yahoo!? Talk to your friends online with Yahoo! Messenger. http://im.yahoo.com -- To UNSUBSCRIBE, email to [EMAIL PROTECTED] with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]
BlackDown JDK and Linux on IA64
Hi, Got two general questions here. Could someone provide some info? Thank you. Lee === Q1: If the current Balckdown JDK will be compatible with Linux64 and Intel IA64 platform? If not, any plan or info. on this? Q2: Can we freely distribute BlackDown jre (not jdk) to customers to let them run our java applications? I think someone may already asked similar questions before. -- To UNSUBSCRIBE, email to [EMAIL PROTECTED] with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]
JNI & _init() function in .so file
Hi, Got two questions on JNI and .so file. It would be appreciated if someone could help. Q1: I was told that when java jni loads .so file, the first function been called is _init(). Can I use it as a constructor to setup something when java app loads the .so file? If I put _init() func in .so C source file, compiler generates an error msg "multiple definition of '_init', /usr/lib/crti.o:first definition here". Q2: After java jni loads a .so file, how can I find the number of links to the .so file from a command line command and a lib call? Thank you. Lee -- To UNSUBSCRIBE, email to [EMAIL PROTECTED] with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]
exec() on Linux
Hi:
I got
a java application that uses exec("nativeApp.exe") to start a native
application. It works fine on NT. But on Linux exec("a.out") gets an
exception saying a.out could not be found. a.out is placed in the same
directory as java app does. What I missed?
Thank
you.
Lee
RE: Java app and Native Processes on Linux
Hi:
I'm
trying to use two java threads t1 and t2, and each one uses exec() to start the
same C native application. It seems JVM (BlackDown 1.1.8 v1) never
switches from t1 to t2. The output looks like:
In
thread t1: i = 0
In
thread t1: i = 1
In
thread t1: i = 2
...
I put
suspend() inside method run(), but it couldn't stop t1 from running. What
I missed?
The
attached C and java codes are real and can be compiled.
Thank
you.
Lee
---
/ C application source
code/
#include
int main(int argc, char*
argv[]){ int
i; for(i=0;
i<1000; i++)
{
printf("In thread %s: i = %d\n", argv[1],
i);
fflush(stdout); sleep(1); }
return
0;}
===
/ java
application source
code/import
java.lang.*;import java.io.*;
class communicate{
public static void main(String args[]) { myThread t1 = new
myThread("t1"); myThread t2 = new
myThread("t2");
t1.run();
t2.run(); }}
class myThread extends
Thread{ String szThreadName;
myThread(String
szName) {
super(szName);
szThreadName = szName; }
public void
run() { Process
proc_; int rc; char[] buf
= new char[1024]; File
fileObj = new File("a.out"); String
fileName = fileObj.getAbsolutePath();String
cmd[] = new String[2]; cmd[0] =
fileName; cmd[1] =
szThreadName;
try
{
System.out.println("the executable name
is:"+fileName);
proc_ =
Runtime.getRuntime().exec(cmd);
BufferedReader in = new BufferedReader(new
InputStreamReader(proc_.getInputStream()));
do
{
rc = in.read(buf);
if(rc>0)
System.out.print(buf); suspend(); // why this suspend() doesn't
work???
}while(rc != -1);
} catch(IOException
e)
{
System.out.println("got e after try
exec()");
e.printStackTrace(); } } // end of run()} // end of myThread class
Source Code of Web Browser for Linux
Hi: Is there any source code of a Web browser for Linux available somewhere? It's even better if it's pure Java source code, so we can use it on different platform to get a consistent interface? Thanks. Lee -- To UNSUBSCRIBE, email to [EMAIL PROTECTED] with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]
How to use Java options -Xms and -Xmx on Linux?
Hi, It would be appreciated if someone could help me on the following questions. Q1: can I use "k", "m" and "g" to specify kbyte, mbyte and gbyte, like -Xms700m (for 700 mb), -Xmx2g (for 2 gb)? Q2: is there any upper limit for -Xms and -Xmx values, or can I use whatever value I want such as -Xms700m and -Xmx2g (suppose "m" and "g" are available)? Q3: should I consider the actual physical memory size when I specify -Xms and -Xmx values? Q4: Windows use memory paging, so if I use larger -Xms and -Xmx values than physical memory size, paging occurs and paging activity may slow down Java application execution. Does Linux use paging in the same way as Windows does? Q5: is there any document which explain how to use -Xms and -Xmx in more details? Thank you. Lee -- To UNSUBSCRIBE, email to [EMAIL PROTECTED] with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]
