As no synchronization b[Oetween the started threads exists, all the possible permutations of ``tX'' where $x$ is 1, 2 or 3 are valid outputs. Namely, all possible combinations are: \marginpar[right
\item No, as the method is \texttt{synchronized} and requires a mutually exclusive lock to be acquired to execute it, therefore only one thread at a time can execute;
\item Yes, as \textit{getCounter()} is not marked with the \texttt{synchronized} keyword;
\item Yes, as one thread may acquire the lock for \textit{incrementCounter()} while the other just released it and is executing \textit{getCounter()};
\item Yes, as the updates to the \textit{count} variable in \textit{Counter} are atomic and safe,
therefore the count will always be exact;
\item The object will acquire and release the intrinsic lock of the \textit{counter} object defined at line 17.
\end{enumerate}
\section*{Exercise C: Concurrency}
No, as the foreach loops may indeed run simultaneously. According to the Java 17 standard library documentation for \texttt{Collections.synchronizedList(...)}\footnote{\url{https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/util/Collections.html\#synchronizedList(java.util.List)}}, in order to obtain such access behaviour we would need to use the intrinsic lock of the list object wrapping the foreach loop with a \texttt{synchronized (integerList)} block.
\section*{Exercise D: JVM Architecture}
\begin{enumerate}
\item As invoking \texttt{javap Secret} reports:
\begin{verbatim}
Warning: File ./Secret.class does not contain class Secret
Compiled from "Login.java"\end{verbatim}
the name of the original Java file is \texttt{Login.java};
\item According to the output of \texttt{javap -c -l Secret}, specifically these lines:
\begin{verbatim}
0: ldc #55 // String Hello, try to find the username and the password [...]
71: ldc #79 // String Congratulations, now write the username and the [...]
[...]
LineNumberTable:
line 27: 0
[...]
line 41: 68
line 42: 76
[...]\end{verbatim}
the string starting with ``Hello'' is stored in tag 55 of the constant pool and is loaded at line 27. The string starting with ``Congratulations'' is stored in tag 79 of the constant pool and is loaded at line 42.
\item According to the output of \texttt{javap Secret} showing the class's interface:
\begin{verbatim}
public class Login {
public Login();
public static char transform(char);
public static boolean access(java.lang.String, java.lang.String);
public static void main(java.lang.String...);
}\end{verbatim}
there are three \texttt{public static} methods in the class.
\end{enumerate}
To aid the explanation of how we found the secret password we report the full output of
\item The output of the command \texttt{java -XX:+UnlockDiagnosticVMOptions -XX:+PrintInlining Inlining} is the following:
\begin{verbatim}
@ 17 java.lang.String::isLatin1 (19 bytes) inline
@ 27 java.lang.StringLatin1::hashCode (42 bytes) callee is too large
@ 37 java/lang/StringUTF16::hashCode (not loaded) not inlineable
@ 6 java.lang.String::coder (15 bytes) inline
@ 6 Point::<init> (15 bytes) inline
@ 1 java.lang.Object::<init> (1 bytes) inline
@ 20 Point::getY (5 bytes) inline
@ 25 Point::setX (6 bytes) inline
@ 30 Point::setY (6 bytes) inline
@ 6 Point::<init> (15 bytes) inline
@ 1 java.lang.Object::<init> (1 bytes) inline
@ 20 Point::getY (5 bytes) inline
@ 25 Point::setX (6 bytes) inline
@ 30 Point::setY (6 bytes) inline
@ 20 Point::getY (5 bytes) accessor
@ 25 Point::setX (6 bytes) accessor
@ 30 Point::setY (6 bytes) accessor\end{verbatim}
Therefore we can confirm that all methods listed were inlined while executing class \textit{Inlining}.
\end{enumerate}
\section*{Exercise F: Java Agent}
\begin{enumerate}
\item The compiled code given cannot be executed as-is as the class \textit{ch.usi.inf.ajp22.Point} contains an invalid java class file format version of 255 (where e.g. for Java 17 the correct value is 61).
\item Please find the relevant source code in folder \texttt{ExcerciseF}.