What is @(#) in source files?

A

Alex

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
 
T

Thomas Weidenfeller

Alex said:
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
 
B

Betty

Thomas Weidenfeller said:
Alex said:
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;
 
W

Wayne

Thomas said:
Alex said:
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
 
D

Dale King

Betty said:
Alex said:
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.
 
D

Dale King

Wayne said:
Thomas said:
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.
 
W

Wayne

Dale said:
Wayne said:
Thomas said:
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
 
T

Thomas Weidenfeller

Wayne said:
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
 

Ask a Question

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

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

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,680
Members
48,796
Latest member
Greg L.

Latest Threads

Top