Thread: PG functions in Java: maybe use gcj?
I had an interesting conversation today with Tom Tromey and Andrew Haley of Red Hat about how to implement "pljava" for Postgres. Rather than futzing with an external JVM, their thought is to use gcj (gcc compiling Java). It sounds like this approach would mostly just work, modulo needing to use a small amount of C++ code to call the defined APIs for gcj. This would not be a perfect solution: gcj isn't yet ported everywhere, and it would probably not play nice on machines where the standard C library isn't thread-safe. But it seems a lot more within reach than the approaches we've discussed in the past. I'm not volunteering to try to do this, but I wanted to toss the idea up in the air and see if anyone wants to try it. Tom and Andrew indicated they'd be willing to help out with advice etc for anyone who wants to take on the project. regards, tom lane
I am not sure I follow. Are you suggesting: 1) create function takes java source and then calls gcj to compile it to native and build a .so from it that would get called at runtime? or 2) create function takes java source and just compiles to java .class files and the runtime invokes the gcj java interpreter. or I guess you could do both at the same time. In either case I am concerned about licensing issues. gcj is not under a BSD style license. Depending on what you need you are either dealing with regular GPL, LGPL, or LGPL with a special java exception. I beleive (without giving it too much thought) that doing either 1 or 2 above would end up linking GPL code into postgres. This can be worked around by requiring the the necessary gcj libraries be installed separately and detected at configure time (like is done elsewhere). But is does (I think) present a problem for commercial products that would like to redistribute postgres with pljava. Another challenge here it that the java code is going to want to use the jdbc api when communicating with the database. One difficulty here is getting jdbc to be part of the same transaction as the calling java function. Such that if the java stored procedure selects or updates data it is doing it in the same transaction as the caller of the function. Today the jdbc driver only knows how to communicate via the FE/BE protocol which will end up creating a new process and transaction. The jdbc driver would need to not use the FE/BEprotocol but instead probably use jni calls. thanks, --Barry Tom Lane wrote: > I had an interesting conversation today with Tom Tromey and Andrew Haley > of Red Hat about how to implement "pljava" for Postgres. Rather than > futzing with an external JVM, their thought is to use gcj (gcc compiling > Java). It sounds like this approach would mostly just work, modulo > needing to use a small amount of C++ code to call the defined APIs for > gcj. > > This would not be a perfect solution: gcj isn't yet ported everywhere, > and it would probably not play nice on machines where the standard C > library isn't thread-safe. But it seems a lot more within reach than > the approaches we've discussed in the past. > > I'm not volunteering to try to do this, but I wanted to toss the idea > up in the air and see if anyone wants to try it. Tom and Andrew > indicated they'd be willing to help out with advice etc for anyone > who wants to take on the project. > > regards, tom lane > > ---------------------------(end of broadcast)--------------------------- > TIP 2: you can get off all lists at once with the unregister command > (send "unregister YourEmailAddressHere" to majordomo@postgresql.org) >
Barry Lind <blind@xythos.com> writes: > I am not sure I follow. Are you suggesting: > 1) create function takes java source and then calls gcj to compile it > to native and build a .so from it that would get called at runtime? > or > 2) create function takes java source and just compiles to java .class > files and the runtime invokes the gcj java interpreter. > or I guess you could do both at the same time. The impression I had (after not looking very closely) was that you could expect to compile to bytecodes on the fly and then run the gcj interpreter. But the .so alternative might be a good fallback if that doesn't work. > In either case I am concerned about licensing issues. gcj is not under > a BSD style license. Depending on what you need you are either dealing > with regular GPL, LGPL, or LGPL with a special java exception. > I beleive (without giving it too much thought) that doing either 1 or 2 > above would end up linking GPL code into postgres. This can be worked > around by requiring the the necessary gcj libraries be installed > separately and detected at configure time (like is done elsewhere). But > is does (I think) present a problem for commercial products that would > like to redistribute postgres with pljava. Good point, but unless you want to build a BSD-license Java implementation, there will never be a pljava that doesn't have different licensing restrictions than PG itself does. gcj is at least more free than either Sun's or IBM's JVM ... > Another challenge here it that the java code is going to want to use the > jdbc api when communicating with the database. Yes. I think we'd need a new implementation of jdbc that sits atop SPI (invoked via jni I guess) rather than a FE/BE connection. How well layered is our jdbc code --- would this mean a large rewrite, or just rolling in a new bottom layer? regards, tom lane
Tom Lane wrote: > Barry Lind <blind@xythos.com> writes: > >>In either case I am concerned about licensing issues. gcj is not under >>a BSD style license. Depending on what you need you are either dealing >>with regular GPL, LGPL, or LGPL with a special java exception. >>I beleive (without giving it too much thought) that doing either 1 or 2 >>above would end up linking GPL code into postgres. This can be worked >>around by requiring the the necessary gcj libraries be installed >>separately and detected at configure time (like is done elsewhere). But >>is does (I think) present a problem for commercial products that would >>like to redistribute postgres with pljava. > > > Good point, but unless you want to build a BSD-license Java > implementation, there will never be a pljava that doesn't have different > licensing restrictions than PG itself does. gcj is at least more free > than either Sun's or IBM's JVM ... > It depends on what you mean by more free. An architecture that interacts with an external jvm would let you use any jvm (free ones as well as others). From a licensing standpoint it is generally easy to redistribute a jvm or expect the user to have one installed (most java based products out there today do this). However in the proposal here we are talking about requiring a specific jvm (gcj) and actually linking parts of it into postgres. To the extent that GPL code is linked in the GPL extends to the entire code base. As I said previously there are ways to work around this, but it becomes tricky. Especially when a commercial product wants to bundle postgres and pljava. That resulting bundle is probably entirely under the GPL and then any changes to it are also GPL. So it could be the case that this company would be prevented from submitting improvements they made back to the core product because their improvements are GPLed as a result of pljava. Now having said all that, I have been monitoring the progres of gcj for some time because I think there are very interesting possibilities. And I am all for anyone who wants to look into it further and investigate the possiblities. I just want to raise the licensing issue because it can cause problems and it is better to think about them up front than after the fact. > >>Another challenge here it that the java code is going to want to use the >>jdbc api when communicating with the database. > > > Yes. I think we'd need a new implementation of jdbc that sits atop SPI > (invoked via jni I guess) rather than a FE/BE connection. How well > layered is our jdbc code --- would this mean a large rewrite, or just > rolling in a new bottom layer? > It isn't as well layered as it could be, but it isn't too bad. Overall it shouldn't be too much work, but not a little project either. One area that isn't well layered is the assumption that the raw data from the server is in text format, since that is what the FE/BE protocol provides. So all the conversion functions that convert to/from java datatypes do so in this format. This assumption runs deep into the code. As a first pass it would be easiest to get raw data from SPI convert to text and then convert to java datatypes instead of going directly from the internal SPI format directly to java datatypes. This could be improved upon later. > regards, tom lane > thanks, --Barry
On Thu, 2002-10-31 at 18:27, Barry Lind wrote: > However in the proposal here we are talking about requiring a specific > jvm (gcj) and actually linking parts of it into postgres. To the extent > that GPL code is linked in the GPL extends to the entire code base. As > I said previously there are ways to work around this, but it becomes > tricky. Especially when a commercial product wants to bundle postgres > and pljava. That resulting bundle is probably entirely under the GPL > and then any changes to it are also GPL. So it could be the case that > this company would be prevented from submitting improvements they made > back to the core product because their improvements are GPLed as a > result of pljava. Nothing that company does can affect the licensing of PostgreSQL itself - it doesn't belong to them, so they cannot change its licence. Nothing in the GPL forces them to put GPL copyright on their own alterations. What they cannot do is to _distribute_ binary code that links to GPL code while giving fewer rights to their distributees than they themselves received with the GPL code, whether in respect of their own code or the GPL code. Therefore they would be required to make their source changes available to anyone to whom they gave a binary, and they would not be able to restrict the further distribution of those changes. They can contribute those changes to the project under whatever licence they wish that is acceptable to the project. Furthermore, gcj is part of the GNU compiler collection, like gcc, and using it does not in itself cause code compiled under it to be subject to the GPL. Linking to its runtime library would normally cause that, but the gcj-3.0 copyright contains the following text: ======================================================================== The libgcj library is licensed under the terms of the GNU General Public License, with this special exception: As a special exception, if you link this library with other files to produce an executable, this library does not byitself cause the resulting executable to be covered by the GNU General Public License. This exception does not howeverinvalidate any other reasons why the executable file might be covered by the GNU General Public License. ======================================================================== -- Oliver Elphick Oliver.Elphick@lfix.co.uk Isle of Wight, UK http://www.lfix.co.uk/oliver GPG: 1024D/3E1D0C1C: CA12 09E0 E8D5 8870 5839 932A 614D 4C34 3E1D 0C1C ======================================== "But they that wait upon the LORD shall renew their strength; they shallmount up with wings as eagles; they shall run, and not be weary; and they shall walk, and not faint." Isaiah 40:31