Do we admit an admittedly partial list of 'unsafe to inline` methods like this? Does it give a false sense of secuity? Does this problem actually come up in practice? How many folks (other than ourselves) are actually compiling with -optimize?
You already prohibit 2 of 3 reflection APIs which is a good thing, but you should probably also consider adding javax.lang.model, as they plan to add a runtime implementation in the future (by the way, does this sound familiar :-D) and who knows how they manage to mess it up this time.
Anyway, this was a bigger can of worms than I thought, and I'm not sure what to do with this.
+ /**+ * Is this method a caller-sensitive method?+ * I.e., does it call Reflection.getCallerClass or a similer method+ * to ask about the identity of its caller?+ */
Looks like Java will be getting a @sun.reflect.CallerSensitive annotation sooner or later, which we can just check.
Looks like Java will be getting a @sun.reflect.CallerSensitive annotation sooner or later, which we can just check.
Also, this reinforces the wisdom of pursuing the minimal solution.
Have a look at:+ /**+ * Is this method a caller-sensitive method?+ * I.e., does it call Reflection.getCallerClass or a similer method+ * to ask about the identity of its caller?+ */
in http://hg.openjdk.java.net/jdk8/tl/jdk/rev/762eee5e6e16
Your message prompts a much more basic question (which could allow a much simpler fix, namely blacklisting the whole Java class library): how can we ever inline JDK's code while keeping it compatible with changes in the standard Java library? We inline Java method X from JDK library Y, that method's fixed in next release of the JDK, but since the application is not recompiled the fix is not included.
This can have security implication; If we assume that the fix is for a security bug, a Scala application is potentially affected if any Scala code it uses (libraries or the application itself) was compiled with -optimise on a vulnerable machine.Please tell me I'm missing something here. Please.Such problems potentially generalize to any cross-library inlining, but only if the library contained the inlined code is allowed to be upgraded - is that on by default in when you create a POM file? I have no clue on publishing libraries.Also, this gets fun when you inline code from a buggy cryptography library, for instance, or (for different reasons) when you inline enough code to depend on changing implementation details of a library (not sure if that's possible in Scala though).
We have to think very carefully about defaults here, and find a way balance the needs of the 'closed world' users who want maximum performance vs the 'open world' users who need safety in the face of unknown runtime environments.
Is @noinline (http://www.scala-lang.org/api/current/index.html#scala.noinline) germane to this discussion? Does it still do what it says on the tin? Should it be more widely publicized? :)
You mean different versions of the same library, right? We've discussed this, but nobody said yet if e.g. Maven or SBT allow that.
In this thread we already discussed why you want to inline some third-party code, but I'll summarize a few cases:
* You do want to inline at least some code from the Scala standard library.
* In an application you want to do global inlining (where appropriate for performance).
* More in general, in a library you can inline code from another library *iff* that other library is already constrained to a fixed version (which I guess is the case in an SBT project). An application is an instance of this case (since you ship the application together with all its dependencies).
--
Paolo
On 16 January 2013 15:03, Paolo Giarrusso <p.gia...@gmail.com> wrote:
You mean different versions of the same library, right? We've discussed this, but nobody said yet if e.g. Maven or SBT allow that.
Maven potentially allows this by using artifact version ranges. I think osgi has a similar mechanism. My experience is that these are used very sparingly in the wild, but that may just be my personal experience.
In this thread we already discussed why you want to inline some third-party code, but I'll summarize a few cases:
* You do want to inline at least some code from the Scala standard library.
* In an application you want to do global inlining (where appropriate for performance).
* More in general, in a library you can inline code from another library *iff* that other library is already constrained to a fixed version (which I guess is the case in an SBT project). An application is an instance of this case (since you ship the application together with all its dependencies).If you inline across jar boundaries, you're making a commitment to bind to that exact bytecode. This is a much stronger commitment than binding to an API (with or without implied consistent behaviour), which is the contract that is usually modelled using major/minor version numbers.
[...] To my mind, this is another strong argument in favour of small, modular jars - more jars means less bytecode is attached to any given version number. So, if you make a change, more of the inlining remains provably valid.
The alternative is to annotate classes/methods with their inlined dependencies and bytecode checksums, and have some link-time hook in the JVM that validates the checksums for these dependencies. I have no idea how to implement this, and it sounds like a nightmare. I wouldn't wish it on a PhD student.
I would be interested to see how aggressive inlining affects how much work ProGuard can do - I'd hope that explicit references to many library classes would evaporate along the way, but perhaps this is unrealistic.
A summary on how the experimental optimizer goes about inlining can be found at http://magarciaepfl.github.com/scala/
OK. Is it possible for the private var accessors to be marked @inline? I know the JVM will be doing this for me but it is the reduction in bytecode that I really care about here.
Sent from my android - may contain predictive text entertainment.
OK. Is it possible for the private var accessors to be marked @inline?