This discussion is archived
1 2 3 Previous Next 34 Replies Latest reply: Oct 20, 2004 6:25 AM by dcminter RSS

Propose adding opage/inplace object instance to the language

843853 Newbie
Currently Being Moderated

First, for the eager, what this may solve:

1) Much faster JVM because the garbage collection will kick in much less often
2) Much small memory foot print for java application.
3) Provide better scope control (more on this later)
4) Provide faster object copy (something like: deep copy speed of shallow copy)
5) Predictable finallization of object destructor

Please provide more if you see more.

What is the proposal:

First, I would like to say that this is an idea that is not completely thought out. That means it's not perfect, and needs your inputs and other's input to get it there. So please don't just say that does not work because of this, or of that, but add/change/modify it to make it better.

Java have 2 generate types of data: native and object. Native data are interger, float, double, char, etc. Object instances are instances of classes and arrays. Native data is beautiful in a sense that it does not need garbage collected. This means you can declare as many as you want, and at the end of the function call, it will be easily discarded without any problem. Object instances will not be discarded easily like this, except a very smart compiler can detect if the object is not passing around outside of a function/subroutine, then it can be discarded instantly too (except threading, or things like JFrame).

So, to provide the advantage of native data to the object instances, I propose a new keyword to the langage: opaque (or whatever better term). This keyword will go before a variable's declaration:

ex:
opaque MyClass myobj;
opaque MyClass2 myobj("constructor param1", ect...);

Think of opaque objects as C++ object, and currently objects (allocating with new operator) as C++'s pointer. It does not need "new" to allocate a new one.

The functionally of opaque objects will be the same as that of C++ objects. At the end of the function, it will be discarded as that of other native variables.

You cannot use assignment operator with these ("=" without the double quote). You have to use a function:

myobj.copyFrom(myobj2);

This will be memory copy which is much faster (shallow copy, but if there's any opaque member inside of myobj2, it will be copied too). This provides a semi deep copy functionally. Some constraint must exist here. Such as whether can myobj2 be a handle or must it be an opaque object. If it can be a handle, what if it's null, that would generate runtime exception.

Another way would be java.lang.System.copyObject(obj1, obj2);

This is fine, but it's little bit long and coders may not want that. Another way is to use "=", but this may lead to confusion (does it?). The copyFrom can also be override and to throw exception (such as IO class).

With this, you can control the scope of your object well because its not passing around globally like "new" object (this is a major goodness of java, but also a major problem of it). With the new type of object, you can control this totally. Having both the benefit, and can also choose to avoid it if needed.

Most object would not need to be dynamic object (using new). So, the memory foot print will be very small without frequent garbage collection. You can argue that memory should not go up either case. True, but in reality, unless you call garbage collection all the times, there's always the fluctuation of memory up and down (due to objects not discard by gc() and then discarded). You then can argue that memory foot print could actually go up. True, but not much. This is due to the fact that an object will exist to the end of its scope before it can be collected (such as the end of a function or the end of a block). This is very temporary for current operation/object. Also, you can switch to dynamic object if this is a big issues. Using clear scope, you can also limit this successfully in some cases (declare opaque object instance inside { .. } where it's only used).

There you go. Please contribute your ideas. If this proves to be a great feature of the language, please raise your voice, and hopefully someday it will be incorporated into the language.













  • 1. Re: Propose adding opage/inplace object instance to the language
    dcminter Newbie
    Currently Being Moderated
    First, I would like to say that this is an idea that
    is not completely thought out.
    No kidding.

    You give the distinct impression that you don't know the difference between heap and stack allocation, you misuse the terminology dreadfully, and the rest of your argument is riddled with fairly deep misunderstandings.
    Please contribute your ideas.
    My idea, well, more an opinion, is that this would add nothing of value to the language. If you're convinced I'm wrong, I suggest you write up an RFE or JCP draft.

    Dave.
  • 2. Re: Propose adding opage/inplace object instance to the language
    843853 Newbie
    Currently Being Moderated

    It's nice to get a feedback. But sadly, the feedback was not a feedback, but a ridicule. If you don't mind, please tell me:

    1) what heap and stack has anything to do with this?
    2) What part is misunderstanding and why?
    3) Why it does not add value to the language.
    4) Why would write a RFE or JCP draft would convinced me of anything
    5) Why that's the best option to just get convinced? (seems alot of work to just get convinced don't you think?)
    6) Can you go over point by point, which of my suggestion is flawed?
    7) Which terminology is misused? Why is that so? Can it be changed to another term? Or since I suggested this (I don't know if I am the first), do I have the right to call it whatever I want? Who came up with the Java name in the first place, and why coffe has anything to do with programming?

    Thanks.
  • 3. Re: Propose adding opage/inplace object instance to the language
    dcminter Newbie
    Currently Being Moderated

    > But sadly, the feedback was not a feedback, but a ridicule.

    That was not ridicule. You don't qualify for ridicule. I'm just pointing out that you have no clue what you're talking about.

    > 1) what heap and stack has anything to do with this?

    Variables local to a function get allocated on the stack. Objects get allocated on the heap (although their references tend to get allocated on the stack).

    > 2) What part is misunderstanding and why?

    Pretty much all of it.

    Because you're ignorant ?

    > 3) Why it does not add value to the language.

    One of the strong points of Java is the strictly GC memory model.

    > 4) Why would write a RFE or JCP draft would convinced me of anything
    5) Why that's the best option to just get convinced?
    (seems alot of work to just get convinced don't you
    think?)

    Convince you ? I don't need to convince you; you're obviously enamoured of your crappy idea. But if you intend to persuade anyone else that it's a good idea, yammering on in the Java Forums won't get you anywhere; you need to put this sort of change through the JCP (and fat chance of getting anywhere).

    And if you want a new feature in the language which will potentially cause problems for everyone concerned, it's only reasonable to expect a bit of effort from you to go about introducing it. Or do you think we should write it for you ?

    A rule of thumb - if you don't know how to create a compiler to implement your new feature, you're not qualified to comment on the value of that new feature. If you are qualified to implement such a compiler, we'll listen to you when you've done so.

    > 6) Can you go over point by point, which of my suggestion is flawed?

    No. I really can't be arsed. I actually don't care that much, because you're so obviously talking bollocks.

    > 7) Which terminology is misused? Why is that so?

    Here's an example:
    "Java have 2 generate types of data: native and object."

    Just SO wrong.

    Again, because you're ignorant ?


    > Can
    Who came up with
    the Java name in the first place

    Who cares ? Gosling or Sun marketing.

    >, and why coffe has
    anything to do with programming?

    Please tell me you're kidding.

    You don't know the terminology, you don't have the faintest idea how the Java memory model works, you think GC is a bad idea. I'm guessing you're a bad C++ programmer who's transferred to Java and things that he's a bad Java programmer because of "missing" features from C++.

    Give me a single reason why anyone would care what you think.

    Dave.
  • 4. Re: Propose adding opage/inplace object instance to the language
    843853 Newbie
    Currently Being Moderated

    First off, I want to say that some of the words I used was incorrect. I think if someone can understand it, then that's fine to me.

    On the JCP, I think talking to people first, like this forum. Then gather ideas, discussion, then if it's any good, then go to the JCP or whatever if needed. So say going straight to the JCP to propose something is very immature.

    To go to the points you pointed out, on the heap and stack. Who care what get allocated where. That's your way of doing it. Did you ever program in c++? If you can copy an object, using memory copy, then that's what I am talking about. It points out that's possible. I am not saying that's the only way of doing it.

    My suggestion above does not violate any GC memory model. Maybe you did not read it careful enough. And what memeory model? Did you know that GC memory model was changed lately? Mind you, anything could get changed, and get better, if it can. I think you better read my suggestion again, think hard, and think why it's possible to create a GC that can do this.

    About convincing. Unless you're the one that is ignorant, helping someone else to clear his/her point, or adding valuable point is the opposite of ignorant. I do not "yammering" on this forum. If my idea is bad, I'll take it as bad with constructive comment. That's all fine. This is where people talks and contribute idea. It's called a forum. My intention was to get constructed comment, not like yours. It doesn't matter it's crappy idea or not. You are the one who mention about "convinced" in the first place.

    I have to disagree with your rule of thumb. That's called ignorant. Anyone can contribute idea. The ignorant one ignore them. Idea can be good or bad, but out of many ideas, there'll be a good one or two. Even though my idea could be bad. That's why I put it up here for people to discuss it.

    Saying Java generates native and object data. That could be wrong, but if someone could understand it, that's fine by me. If you don't understand it, then don't say that's wrong, because you don't have a clue of what's wrong and right. If you do, yes, you can pick on me for that. I am ok with that. But my point was that when you said something, then point out what it is, and why it is so. Even in this case, you still say: "that's so wrong". What's that?

    Bad C++ programmer? That's subjective. From my workers at work, developer friends, back in school, my record didn't ever show that I was a bad C++ programmer when they look at my work, or my code. I have worked with rock solid C++ commercial program and that product didn't have problem with memory, or thing like that. Without go too far with this because it becomes a boast, I have to stop here.

    Go back to my original idea, I think you probably didn't get it, or you're too ignorant for this to not get it, or you just want to pick a fight. If you look at C++, it obviously works, so don't you tell me to go and implement a C++ compiler to prove my point. C++ has both dynamic allocated object, and statically allocated object. My idea was that to mark object statically so that when it goes out of scope, it'll get discarded. About the GC, it basically does the job of cleaning up all these dynamically allocated objects. So it should not interfere with the statically allocated object. It's like C++ with GC (ofcourse with some modification, probably some product provides GC for c++ already, try search for Smartheap or something like that). Why I said "what stack and heap has anything to do with this?" Your answer was how static and dynamic memory get allocated, not what it has anything to do with this. Here's my point if you don't get it yet. The static memory get allocated in the stack, like you said, and the dynamic memory get allocated in the heap, like you said. So what! Whatever on the stack, get discard when it's out of scope, and the stuff on the heap is GCed.

    when did I say GC was a bad idea? Did I say discard the GC in Java? I did recognized that the current GC pauses Java program quite alot for many big Java app (need me to give your example on this?). I also did noted that Java program tend to have large memory foot print, and that could be helped by doing this. The part that helps is the one that reduce the wildly fluctuate memory usage (befed GCed and after GCed). And the reason I think it's possible to alliviate this is to introduce way not to use dynamically generated object beside dynamically generated object (not get rid of it, but provide both functionality). Many C++ program can be written with very few dynamically generated object. I think the GC would be faster if less pointer/handle to scan, and less dynamically generated object for it to process. No, I don't like to hear the "go back to C++" talk. But, anything is good in C++, it'll be nice to bring over to Java. Remember that Java brough many ideas from C++, and there's nothing wrong with that.









  • 5. Re: Propose adding opage/inplace object instance to the language
    dcminter Newbie
    Currently Being Moderated
    I think if someone can understand it,
    then that's fine to me.
    If you don't use your terminology accurately, different people will think you mean different things. That's why we have terminology.

    Furthermore, not knowing the terminology casts grave doubts on your understanding of the problem.
    So say going straight to the JCP to propose something
    is very immature.
    I know of no JCPs that have been effected by nattering about them on the forums. You can try to be the first if you like.
    Who care what get allocated where.
    The compiler writer ?
    That's
    your way of doing it.
    Me and Mr Von Neumann.
    Did you ever program in c++?
    Yes. Extensively.
    My suggestion above does not violate any GC memory
    model.
    You were talking about a stack based system, though you didn't know it.
    Maybe you did not read it careful enough. And
    what memeory model? Did you know that GC
    memory model was changed lately?
    It's always been a GC system. It's currently a mark and sweep, though it may at some early stage have been reference counting (though I don't think so).
    About convincing. Unless you're the one that is
    ignorant, helping someone else to clear his/her point,
    or adding valuable point is the opposite of ignorant.
    I'm helping to clarify the fact that you don't know anything about this. Can you write a compiler ? If not, what makes you think you're competent to advise those who can ?
    I have to disagree with your rule of thumb. That's
    called ignorant. Anyone can contribute idea.
    "A fool can ask a question that the wisest man cannot answer"

    That doesn't make fools any better company. And wise men ask more interesting questions.
    That's why I put
    it up here for people to discuss it.
    And see how we leap with joy.
    Bad C++ programmer? That's subjective. From my
    workers at work, developer friends, back in school, my
    record didn't ever show that I was a bad C++
    programmer when they look at my work, or my code. I
    have worked with rock solid C++ commercial program and
    that product didn't have problem with memory, or thing
    like that. Without go too far with this because it
    becomes a boast, I have to stop here.
    As you say it's subjective. Subjectively, I think your co-workers might be idiots too.
    If you look
    at C++, it obviously works
    If you look at C++, it's a different language.
    so don't you tell me to go
    and implement a C++ compiler to prove my point.
    I'm asking you to write a Java compiler to prove that it's worth bothering to do so. If you don't want to, why should we ?

    (Snip massive misconception of how C++ memory model works, ignorance of how your solution will affect GC, and whining self-justificatory waffle).

    You're writing long, boring posts about how wonderful an idea this is, despite not understanding how Java works, not understanding how C++ works, and not getting any response other than my faintly derisive commentaries. I have a new word for your dictionary: "humility".

    Dave.
  • 6. Re: Propose adding opage/inplace object instance to the language
    dcminter Newbie
    Currently Being Moderated
    Just to clarify your dumb idea, tell me what you expect the output of the following program to be:
    import java.util.*;
    public class Foo {
       public static void main(String[] argv) {
          List list = new ArrayList();
          list.add(o);
          Object o = foo(list);
          System.out.println("Returned object: " + o);
          System.out.println("List size is now: " + list.size());
       }
    
       public static Object foo(List list) {
          inplace Object o = new String("World");
          list.add(o);
          return o;
       }
    }
  • 7. Re: Propose adding opage/inplace object instance to the language
    dcminter Newbie
    Currently Being Moderated

    Erratum: delete the list.add(o); line from the main method.
  • 8. Re: Propose adding opage/inplace object instance to the language
    843853 Newbie
    Currently Being Moderated

    I don't need to implement Java compiler. Sun already did that. But I can implement a compiler, and an interpretor that can execute my functionality that I described. It won't completely be a "new" java compiler, but that's not a point. It does not have to do all the stuff Java supported to show a point. As long as it does garbag collection, and static/dynamic object, I think that'll show the point.

    You think that if I can show that, you'll agree on my point? Or you'll keep going on and on picking on my words?

    Many of my points, you do not reply. You say Java and C++ are different. Who says it's the same, but my point was that if C++ can provide this, it means it's possible to do so in Java.

    Talking about humble, I don't afraid of being wrong, or admit publicly that I am wrong. I don't call people stupid or idiots. I just try to clear my point, and recognized that it could be wrong, and it needs people's input/help. Humble is always good, but I have a sense that you may have done something in Java compiler and think you know too much, and just disregard people's idea completely just because some particular point people said is wrong, and miss the big picture of what people say.

    Anyway, I am not going to write too much, since it's obviously you didn't care on each point that I write, so what good is this.
  • 9. Re: Propose adding opage/inplace object instance to the language
    dcminter Newbie
    Currently Being Moderated
    I don't need to implement Java compiler. Sun already
    did that. But I can implement a compiler, and an
    interpretor that can execute my functionality that I
    described.
    Ok, off you go then.
    You think that if I can show that, you'll agree on my
    point?
    No, because I think it's a stupid addition. But I'll consider the possibility that you at least know what you're talking about.
    Or you'll keep going on and on picking on my
    words?
    Language implementation is all about picking on words, so yep, I'll still do that.
    if C++ can provide this, it means it's
    possible to do so in Java.
    I didn't say it was impossible, I said it was a bad idea. Java and C++ are different languages with different strengths. Java's is largely its use of a GC memory model, which your ludicrous idea would subvert horribly.

    (Snip whiny blah blah)

    I think you should be more humble, because you write very long boring posts about a pointless language "feature".

    Dave.
  • 10. Re: Propose adding opage/inplace object instance to the language
    843853 Newbie
    Currently Being Moderated
    From your code:

    This shows that you didn't read my message right. Who say you can add an inplace object to a list? Does the list prototype/declaration allow it to add an in place object? Like it did not allow list to add an integer or whatever (other than recently, they autobox the thing, so with inplace, there has to be a defined spec on what to do with this. Such as shoud it be auto-generated a new dynamic object for this, or generate errror. Remember I mentioned about exception for assignment with I/O class, same here, some way of specifying copy constructor is needed for passing inplace object to function. Ofcource, there's many thing needs to spec out for this to work).

    With in place object, there must be a different between inplace and handle/pointer in declaration, parameter, etc. You cannot mix them, or use them in place of another, unless there's a spec that states exactly the behavior for this.

    I think you try to point out that thing get discarded and then referred somewhere else. Why would you allow that to happen. The "return o" should return a copy of that object (unless error as I said). list.add(o) is already discussed above.

    About:
    Object o = foo(list);

    It shows you didn't read my original message. I did say that care must be taken between pointer/handle and inplace object. Spec has to be written about assignment between inplace object and pointer/handle.

    Object o is a handle/pointer, while foo obviously return an inplace object.

    You mistaken "static" keyword and inplace. They're not the same here. It should be:

    public inplace Object foo(List list)

    instead.

    If you program extensively in C++, you don't assign "C++ static" object to pointer, or the other way around. You have to derefernce the object. I am not saying this is the way to do it here, but I am saying you cannot do blind assignment.

    Oneway to do this is this: (note, this is just one way of doing this).

    import java.util.*;
    public class Foo {
    public static void main(String[] argv) {
    List list = new ArrayList();
    inplace Object o = foo(list);
    System.out.println("Returned object: " + o);
    System.out.println("List size is now: " + list.size());
    }

    public inplace Object foo(List list) {
    inplace Object o = new String("World");
    //list.add(o); //illegal, changed to:

    Object o2 = new String(o); //add a new constructor to String: public String(inplace String s)
    list.add(o2);

    return o;
    }
    }







  • 11. Re: Propose adding opage/inplace object instance to the language
    dcminter Newbie
    Currently Being Moderated
    Oh, great, you can't even use [code] tags properly.

    Does this make you any happier ?
    import java.util.*;
    public class Foo {
       public static void main(String[] argv) {
          InplaceArrayList list = new ArrayListThatCanTakeInplaceObjectsAsParameters();
          inplace Object o = foo(list);
          System.out.println("Returned object: " + o);
          System.out.println("List size is now: " + list.size());
    }
    
       public inplace Object foo(InplaceArrayList list) {
          inplace Object o = new String("World");
          list.add(o);
          return o;
       }
    }
    I'm assuming that it's possible to declare a List type, with whatever syntax you've pulled out of your butt crack, that will accept "inplace" objects.

    My original question still stands, what do you expect the output to be ?

    Dave.
  • 12. Re: Propose adding opage/inplace object instance to the language
    843853 Newbie
    Currently Being Moderated

    //comment:
    inplace Object o = new String("World");
    This should have been changed to:
    inplace String o("World");

    The expected output would be:

    Returned object: World
    List size is now: 1
  • 13. Re: Propose adding opage/inplace object instance to the language
    dcminter Newbie
    Currently Being Moderated
    Either your inplace object can't get free'ed until no references to it exist or it will be freed as soon as the last inplace variable passes out of scope.

    In the former case, you "leak" the rest of the stackframe while anything has access to a variable belonging to it.

    In the latter vase, you permit objects in external collections to mysteriously disappear as their originating variable passes out of scope.

    Equally awful either way.
  • 14. Re: Propose adding opage/inplace object instance to the language
    843853 Newbie
    Currently Being Moderated

    You don't understand a thing about this. That's why I didn't bother answer what the expected output in previous post.

    There's no leak or whatever.

    The list has to autobox the thing into a dynamic pointer (such as create a new object, and copy the content) for the inplacesupportedlist to work.

    The return of the inplace object, if you know C++, unless it's by reference (which you are not allowed to do here), a copy of the object is returned, not the original, and then the content of that get copied into the original variable, and the temporary object get discarded. It's all about spec. Nothing wrong with the program. Now, I know how much you know C++. Kind of wasted my time.

    First, your vulgar language shows the type of person you are. And I prefer not to talk to people like that if I have a choice.

1 2 3 Previous Next