There are many methods in the Java API that are intrinsics, but still have code associated with them when looking at the source code.
For an example, Integer.bitCount() is an intrinsic, but if you open the Integer class file, you can see code with it.
What purposes might this code serve if it is not necessarily used by the compiler/jvm?
An intrinsic function is a function that performs a mathematical, character, or logical operation. You can use intrinsic functions to make reference to a data item whose value is derived automatically during execution.
If a function is an intrinsic, the code for that function is usually inserted inline, avoiding the overhead of a function call and allowing highly efficient machine instructions to be emitted for that function.
JavaScript provides intrinsic (or "built-in") objects. They are the Array , Boolean , Date , Error , Function , Global , JSON , Math , Number , Object , RegExp , and String objects.
As per wiki, the definition of Intrinsic
Function is as follows:
In compiler theory, an intrinsic function is a function available for use in a given programming language whose implementation is handled specially by the compiler. Typically, it substitutes a sequence of automatically generated instructions for the original function call, similar to an inline function. Unlike an inline function though, the compiler has an intimate knowledge of the intrinsic function and can therefore better integrate it and optimize it for the situation. This is also called builtin function in many languages.
Further it says, important and relevant to your question:
Compilers that implement intrinsic functions generally enable them only when the user has requested optimization, falling back to a default implementation provided by the language runtime environment otherwise.
So, it means a default implementation is used most of the time until optimization is not requested or possible (this depends on which machine/configuration JVM is running on). JVM can replace the whole Integer.bitCount()
code to an optimized machine code instruction.
Further, check this discussion which explains the point nicely with an example code.
A default implementation is provided in case there's no possibility of using the intrinsic version, i.e running on a platform for which no intrinsic version is provided.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With