What is @(#) in source files?

Discussion in 'Java' started by Alex, May 18, 2005.

  1. Alex

    Alex Guest

    Hi,

    Does anyone know what is @(#) in the beginning of each jdk source file?
    How is it used? Is it a javadoc tag?

    Example:

    /*
    * @(#)Object.java
    *
    */

    Alex
    Alex, May 18, 2005
    #1
    1. Advertising

  2. Alex wrote:
    > Does anyone know what is @(#) in the beginning of each jdk source file?
    > How is it used? Is it a javadoc tag?


    Oh you are a young grasshopper. This is the SCCS marker string intended
    for the 'what' program.

    SCCS (Source Code Control System) is an a age-old version control
    system. In fact, it is the original UNIX version control system (long
    ago most people dropped it for the free RCS version control system,
    which people later often dropped for the free CVS version control
    system, which in turn is about to be dropped by people for the
    Subversion version control system ...)

    The idea is to have a marker in a file (source or binary) which can
    easily be distinguished from other data. The 'what' program simply looks
    for text of the form '@(#) ... \0' in all kinds of files, and prints the
    text.

    If one combines this with SCCS' ability to expand keywords during
    checkout, you can get automatically correctly labeled source code. If
    you compile the data into a binary, you can trace the binary back to the
    source from which it was build.

    This works better in C than in Java. If you write something like

    char sccsid[] = "@(#)text";

    in C it ends up as the correct byte sequence in the binary (the trailing
    '\0' is implicit in C strings. but in Java it isn't, and you can't just
    insert an own \0 in the string. Well, you can, but Java encodes the \0
    not as a 00, but as C0 80 (which is not well formed UTF-8, but common).

    .. If you do the equivalent in java

    String sccsid = "@(#)text";

    you have to find a way to get the \0 into that string. This is left as
    an exercise to the reader.

    The real question is why Sun still uses the age old SCCS. Well, AFAIK it
    is still the base for Sun's Teamware / Forte Code Management Software
    version control system. Also AFAIK Teamware is not a big player in the
    commercial version control software market.

    /Thomas


    --
    The comp.lang.java.gui FAQ:
    ftp://ftp.cs.uu.nl/pub/NEWS.ANSWERS/computer-lang/java/gui/faq
    Thomas Weidenfeller, May 18, 2005
    #2
    1. Advertising

  3. Alex

    Betty Guest

    "Thomas Weidenfeller" <> wrote in message
    news:d6f149$k36$...
    > Alex wrote:
    > > Does anyone know what is @(#) in the beginning of each jdk source file?
    > > How is it used? Is it a javadoc tag?

    >
    > Oh you are a young grasshopper. This is the SCCS marker string intended
    > for the 'what' program.
    >
    > SCCS (Source Code Control System) is an a age-old version control
    > system. In fact, it is the original UNIX version control system (long
    > ago most people dropped it for the free RCS version control system,
    > which people later often dropped for the free CVS version control
    > system, which in turn is about to be dropped by people for the
    > Subversion version control system ...)
    >
    > The idea is to have a marker in a file (source or binary) which can
    > easily be distinguished from other data. The 'what' program simply looks
    > for text of the form '@(#) ... \0' in all kinds of files, and prints the
    > text.
    >
    > If one combines this with SCCS' ability to expand keywords during
    > checkout, you can get automatically correctly labeled source code. If
    > you compile the data into a binary, you can trace the binary back to the
    > source from which it was build.
    >
    > This works better in C than in Java. If you write something like
    >
    > char sccsid[] = "@(#)text";
    >
    > in C it ends up as the correct byte sequence in the binary (the trailing
    > '\0' is implicit in C strings. but in Java it isn't, and you can't just
    > insert an own \0 in the string. Well, you can, but Java encodes the \0
    > not as a 00, but as C0 80 (which is not well formed UTF-8, but common).
    >
    > . If you do the equivalent in java
    >
    > String sccsid = "@(#)text";


    How about
    String sccsid = "@(#)textq";
    sccsid.charAt(8)=0;

    > you have to find a way to get the \0 into that string. This is left as
    > an exercise to the reader.
    >
    > The real question is why Sun still uses the age old SCCS. Well, AFAIK it
    > is still the base for Sun's Teamware / Forte Code Management Software
    > version control system. Also AFAIK Teamware is not a big player in the
    > commercial version control software market.
    >
    > /Thomas
    >
    >
    > --
    > The comp.lang.java.gui FAQ:
    > ftp://ftp.cs.uu.nl/pub/NEWS.ANSWERS/computer-lang/java/gui/faq
    Betty, May 18, 2005
    #3
  4. Alex

    Wayne Guest

    Thomas Weidenfeller wrote:
    > Alex wrote:
    >
    >> Does anyone know what is @(#) in the beginning of each jdk source file?
    >> How is it used? Is it a javadoc tag?

    >
    >
    > Oh you are a young grasshopper. This is the SCCS marker string intended
    > for the 'what' program.
    >
    > SCCS (Source Code Control System) is an a age-old version control
    > system. In fact, it is the original UNIX version control system (long
    > ago most people dropped it for the free RCS version control system,
    > which people later often dropped for the free CVS version control
    > system, which in turn is about to be dropped by people for the
    > Subversion version control system ...)
    >
    > The idea is to have a marker in a file (source or binary) which can
    > easily be distinguished from other data. The 'what' program simply looks
    > for text of the form '@(#) ... \0' in all kinds of files, and prints the
    > text.
    >
    > If one combines this with SCCS' ability to expand keywords during
    > checkout, you can get automatically correctly labeled source code. If
    > you compile the data into a binary, you can trace the binary back to the
    > source from which it was build.
    >
    > This works better in C than in Java. If you write something like
    >
    > char sccsid[] = "@(#)text";
    >
    > in C it ends up as the correct byte sequence in the binary (the trailing
    > '\0' is implicit in C strings. but in Java it isn't, and you can't just
    > insert an own \0 in the string. Well, you can, but Java encodes the \0
    > not as a 00, but as C0 80 (which is not well formed UTF-8, but common).
    >
    > . If you do the equivalent in java
    >
    > String sccsid = "@(#)text";
    >
    > you have to find a way to get the \0 into that string. This is left as
    > an exercise to the reader.
    >
    > The real question is why Sun still uses the age old SCCS. Well, AFAIK it
    > is still the base for Sun's Teamware / Forte Code Management Software
    > version control system. Also AFAIK Teamware is not a big player in the
    > commercial version control software market.
    >
    > /Thomas
    >
    >


    You have a good memory! Except you forgot to declare the C string as "static".
    This was needed at Bell Labs on SysV to keep SCCS strings in the binaries but
    out of the .data section of the COFF a.out. (This used a modified C compiler
    that created a .SCCS section on the file that, unlike .data, wouldn't auto-load
    into RAM.) When you consider large applications we built in those days were
    build of about 2,000 source files, each with SCCS keyword strings of around 20
    to 60 bytes in length, and also consider the largest mainframes costing
    millions could only have 32 MB of RAM, this made sense.

    In Java you can use:

    String sccsid = "@(#)text\u0000";

    Even if using RCS or CVS with Java, the "what" program can be useful:

    String rcsid = "@(#)$Id$\u0000";

    and RCS will expand the "$Id$" part when you check your code out.

    -Wayne
    Wayne, May 18, 2005
    #4
  5. Alex

    Dale King Guest

    Betty wrote:
    > "Thomas Weidenfeller" <> wrote in message
    > news:d6f149$k36$...
    >
    >>Alex wrote:
    >>
    >>>Does anyone know what is @(#) in the beginning of each jdk source file?
    >>>How is it used? Is it a javadoc tag?

    >>
    >>Oh you are a young grasshopper. This is the SCCS marker string intended
    >>for the 'what' program.
    >>
    >>SCCS (Source Code Control System) is an a age-old version control
    >>system. In fact, it is the original UNIX version control system (long
    >>ago most people dropped it for the free RCS version control system,
    >>which people later often dropped for the free CVS version control
    >>system, which in turn is about to be dropped by people for the
    >>Subversion version control system ...)
    >>
    >>The idea is to have a marker in a file (source or binary) which can
    >>easily be distinguished from other data. The 'what' program simply looks
    >>for text of the form '@(#) ... \0' in all kinds of files, and prints the
    >>text.
    >>
    >>If one combines this with SCCS' ability to expand keywords during
    >>checkout, you can get automatically correctly labeled source code. If
    >>you compile the data into a binary, you can trace the binary back to the
    >>source from which it was build.
    >>
    >>This works better in C than in Java. If you write something like
    >>
    >>char sccsid[] = "@(#)text";
    >>
    >>in C it ends up as the correct byte sequence in the binary (the trailing
    >>'\0' is implicit in C strings. but in Java it isn't, and you can't just
    >>insert an own \0 in the string. Well, you can, but Java encodes the \0
    >>not as a 00, but as C0 80 (which is not well formed UTF-8, but common).
    >>
    >>. If you do the equivalent in java
    >>
    >>String sccsid = "@(#)text";

    >
    >
    > How about
    > String sccsid = "@(#)textq";
    > sccsid.charAt(8)=0;


    That won't even compile, but wouldn't solve the problem even if it did
    as the issue is how to get the string into the class file not how to
    create such a string at runtime.
    --
    Dale King
    Dale King, May 19, 2005
    #5
  6. Alex

    Dale King Guest

    Wayne wrote:
    > Thomas Weidenfeller wrote:
    >> This works better in C than in Java. If you write something like
    >>
    >> char sccsid[] = "@(#)text";
    >>
    >> in C it ends up as the correct byte sequence in the binary (the
    >> trailing '\0' is implicit in C strings. but in Java it isn't, and you
    >> can't just insert an own \0 in the string. Well, you can, but Java
    >> encodes the \0 not as a 00, but as C0 80 (which is not well formed
    >> UTF-8, but common).
    >>
    >> . If you do the equivalent in java
    >>
    >> String sccsid = "@(#)text";
    >>
    >> you have to find a way to get the \0 into that string. This is left as
    >> an exercise to the reader.


    > In Java you can use:
    >
    > String sccsid = "@(#)text\u0000";


    Nope. That is no different than using \0 and as Thomas said that gets
    encoded as C0 80 not as 00.
    --
    Dale King
    Dale King, May 19, 2005
    #6
  7. Alex

    Wayne Guest

    Dale King wrote:
    > Wayne wrote:
    >
    >> Thomas Weidenfeller wrote:
    >>
    >>> This works better in C than in Java. If you write something like
    >>>
    >>> char sccsid[] = "@(#)text";
    >>>
    >>> in C it ends up as the correct byte sequence in the binary (the
    >>> trailing '\0' is implicit in C strings. but in Java it isn't, and you
    >>> can't just insert an own \0 in the string. Well, you can, but Java
    >>> encodes the \0 not as a 00, but as C0 80 (which is not well formed
    >>> UTF-8, but common).
    >>>
    >>> . If you do the equivalent in java
    >>>
    >>> String sccsid = "@(#)text";
    >>>
    >>> you have to find a way to get the \0 into that string. This is left
    >>> as an exercise to the reader.

    >
    >
    >> In Java you can use:
    >>
    >> String sccsid = "@(#)text\u0000";

    >
    >
    > Nope. That is no different than using \0 and as Thomas said that gets
    > encoded as C0 80 not as 00.


    Grrr, I think you're right. This is a puzzler! It is easy to get such
    a string at runtime, or at compile-time using an array of bytes:
    private static byte [] rcsid = { '@', '(', '#', ')', '$', 'I', 'd', '$', \000 };

    Of course this destroys the ability of "get" or "co" or
    "cvs checkout" to expand the "$Id" keyword(s). But do I give up? No!

    Fortunately POSIX defines the "what" program this way:

    .... The what utility shall search the given files for all
    occurrences of the pattern that get (see get ) substitutes
    for the %Z% keyword ( "@(#)" ) and shall write to standard
    output what follows until the first occurrence of one of the
    following:
    " > newline \ NUL
    ....

    So you don't need a NUL at the end, a newline is good enough!
    This works:

    class Foo {
    private static String rcsid = "@(#)$Id$\n";
    }

    The resulting Foo.class file contains the correct string for "what",
    as confirmed by an octal dump. Whew!

    -Wayne
    Wayne, May 19, 2005
    #7
  8. Wayne wrote:
    > Dale King wrote:
    >> Nope. That is no different than using \0 and as Thomas said that gets
    >> encoded as C0 80 not as 00.

    >
    >
    > Grrr, I think you're right. This is a puzzler!


    Ok, I will give it away. You can't get a 0 byte in:

    http://java.sun.com/docs/books/vmspec/2nd-edition/html/ClassFile.doc.html#7963

    Especially:

    http://java.sun.com/docs/books/vmspec/2nd-edition/html/ClassFile.doc.html#2874

    > Fortunately POSIX defines the "what" program this way:
    >
    > ... The what utility shall search the given files for all
    > occurrences of the pattern that get (see get ) substitutes
    > for the %Z% keyword ( "@(#)" ) and shall write to standard
    > output what follows until the first occurrence of one of the
    > following:
    > " > newline \ NUL


    Good catch. I think I didn't look at the 'what' man page in the last 15
    years.

    /Thomas

    --
    The comp.lang.java.gui FAQ:
    ftp://ftp.cs.uu.nl/pub/NEWS.ANSWERS/computer-lang/java/gui/faq
    Thomas Weidenfeller, May 19, 2005
    #8
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.

Share This Page